我正在尝试回答 Spotify 问题Best Before并且我的代码对于我能想到的每个测试用例都能正常工作。但是,根据他们的服务器,我错了。
谁能告诉我我的代码哪里出错了?
这是我的代码:
from itertools import permutations
import datetime
import fileinput
def checkdate(d,m,y):
"""Gets possible values for day, month and year
and generates valid permutations of dates"""
b = permutations([d,m,y])
for p in b:
try:
yield datetime.date(p[0], p[1], p[2])
except ValueError:
yield None
def validvalue(a):
return a > 0 and a <= 2999
c = raw_input()
d,m,y = c.split('/')
d,m,y = int(d), int(m), int(y)
if validvalue(d) and validvalue(m) and validvalue(y):
valid = [x for x in checkdate(d,m,y) if x is not None]
if valid:
print "2" + str(min(valid))[1:]
else:
print "%s is illegal" % c
else:
print "%s is illegal" % c