章鱼哥没有日历(Pyhton实现)

jgzquanquan edited 7 年,5 月前

str_in = input()
a = [int(n) for n in str_in.split(‘-‘)]
month=int(a[1])
day=int(a[2])
mon=[0,31,28,31,30,31,30,31,31,30,31,30,31]
if month>12 or month<=0:
print(‘-1’)
else:
if day<=0 or day>mon[month]:
print(‘-1’)
else:
sum=day
for i in range(month):
sum=sum+mon[i]
print(sum)

Comments

10185102105

s=input()
a=int(s[5:7]);b=int(s[8:10]);r=0
l=[0,31,28,31,30,31,30,31,31,30,31,30,31]
if a>12 or a<1 or b<1 or b>l[a]:print(-1)
else:
for i in range(1,a):
r+=l[i]
r+=b
print(r)