这题。。我大概弄了六七个小时。。一步步改过来。。
最后还是有两个测试点错误。。。
先贴自己的代码。。
d1 = list(input(''))
d2 = list(input(''))
t1 = list(input(''))
t2 = list(input(''))
theday = 0
d_len = min(len(d1),len(d2))
t_len = min(len(t1),len(t2))
k = 0
minu = 0
hour = 0
for i in range(d_len):
if 65<=ord(d1[i])<=71 and d1[i]==d2[i] and theday == 0:
theday = ord(d1[i])-64
continue
elif (65<=ord(d1[i])<=74 or 48<=ord(d1[i])<=57) and d1[i]==d2[i] and theday!= 0:
hour = d1[i]
break
sd = {1:'MON',2:'TUE',3:'WED',4:'THU',5:'FRI',6:'SAT',7:'SUN'}
if hour.isalpha():
hour = ord(d1[i])-55
for k in range(t_len):
if (65<=ord(t1[k])<=90 or 97<=ord(t1[k])<=122) and t1[k]==t2[k]:
minu = k
print(sd.get(theday)+' '+str(hour).zfill(2)+':'+str(minu).zfill(2))
我网上找到的正确的代码。。。。。
但是我真的看不出我跟正确的差在哪里。。
def decipher():
str1 = raw_input()
str2 = raw_input()
str3 = raw_input()
str4 = raw_input()
result = []
for i in range(min(len(str1),len(str2))):
#notice to exclude letters that don't get answer
if str1[i] == str2[i] and str1[i].isupper() and ord(str1[i])-64 < 8:
result.append(str1[i])
continue
#notice to exclude letters that don't get answer
elif str1[i] == str2[i] and len(result) > 0 and (str1[i].isupper() or str1[i].isalnum()) and ord(str1[i])-64 < 15:
result.append(str1[i])
break
for i in range(min(len(str3),len(str4))):
if str3[i] == str4[i] and str3[i].isalpha():
result.append(i)
week = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
result[0] = week[ord(result[0])-64-1]
if result[1].isalpha():
result[1] = str(ord(result[1])-55)
#notice the hour also should have zero in high position
result[1] = str(result[1]).zfill(2)
result[2] = str(result[2]).zfill(2)
print "%s %s:%s"%(result[0], result[1], result[2])
if __name__ == '__main__':
decipher()