3.5 PAT1014 乙级 python [我真实的自闭了]

这题。。我大概弄了六七个小时。。一步步改过来。。

最后还是有两个测试点错误。。。

先贴自己的代码。。

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()

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值