咪咕:笔试题(20190916)

一年的第几天

对闰年的设定根据possible变量来递增,其它则分别进行累加即可。

def the_nth_days(seq):
    if not seq:
        return 0
    months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    values = {
     du: mu for du, mu in zip(range(1, 13), months)}
    possible = 0

    year, month, day = seq[0], seq[1], seq[2]
    if (year % 4 == 0 or year % 100 == 0) and (year % 100 != 0):
        possible = 1
    res = 0
    for mu in range(1, month):
        res += values[mu]
        if mu == 2:
            res += possible
    res += day
    return res


if __name__ == '__main__':
    seq = list(map(int, input().strip().split()))
    res = the_nth_days(seq)
    print(res)

'''
2019 2 2
'''

(最近更新:2019年09月16日)

你可能感兴趣的:(PROGRAM,咪咕,笔试题)