[英]Spotify Best Before program. What am I doing wrong?
I am trying to answer the Spotify problem Best Before and my code works correctly for every test case I can think of. 我想回答这个问题的Spotify 前最佳和我的代码可以正确处理每一个测试用例我能想到的。 However, according to their servers I am wrong.
但是,根据他们的服务器,我错了。
Can anyone please tell me where my code has gone wrong? 谁能告诉我我的代码哪里出错了?
Here is my code: 这是我的代码:
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
From the problem description: 从问题描述:
2000 could be given as "2000", "00" or "0"
2000可以指定为“ 2000”,“ 00”或“ 0”
Your code does not accept 00
or 0
as a valid year. 您的代码不接受
00
或0
作为有效年份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.