原题链接:PTA | 程序设计类实验辅助教学平台
Tips:以下Python代码仅个人理解,非最优算法,仅供参考!
ls=[] #装输入数据,你也可以S1,S2,S3,S4=input(),···
D,H,M='','',''
dict = {'A':'MON','B':'TUE','C':'WED','D':'THU',
'E':'FRI','F':'SAT','G':'SUN'}
#用ord编码,有固定逻辑,也可以用下面字典匹配
# dict1 = {'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,
# 'G':16,'H':17,'I':18,'J':19,'K':20,'L':21,
# 'M':22,'N':23,'O':24}
for i in range(4): #初始4行输入数据
ls.append(input())
#Day判断
_Dindex=0
ran = min(len(ls[0]),len(ls[1]))
for i in range(ran):
if ls[0][i]==ls[1][i] and 'A' <= ls[0][i] <= 'G':
D=dict[ls[0][i]]
_Dindex=i
break
#HH判断
for i in range(_Dindex+1,ran):
if ls[0][i]==ls[1][i] and ('0'<=ls[0][i]<='9' or 'A'<=ls[0][i]<='N'):
if '0'<=ls[0][i]<='9':
H=int(ls[0][i])
break
elif 'A'<=ls[0][i]<='N':
H=ord(str(ls[0][i]))-55
#H=dict1[ls[0][i]] #配合dict1
break
#MM判断
ran = min(len(ls[2]),len(ls[3]))
for i in range(ran):
if ls[2][i]==ls[3][i] and ('a'<=ls[2][i]<='z' or 'A'<=ls[2][i]<='Z'):
M=i
break
print('{} {:02d}:{:02d}'.format(D,H,M),end='')
标签:Python,福尔摩斯,len,ran,range,ls,1014,input
From: https://blog.csdn.net/m0_56677113/article/details/142184949