繁体   English   中英

Spotify Best Before计划。 我究竟做错了什么?

[英]Spotify Best Before program. What am I doing wrong?

我想回答这个问题的Spotify 前最佳和我的代码可以正确处理每一个测试用例我能想到的。 但是,根据他们的服务器,我错了。

谁能告诉我我的代码哪里出错了?

这是我的代码:

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

从问题描述:

2000可以指定为“ 2000”,“ 00”或“ 0”

您的代码不接受000作为有效年份。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM