#19014: 找不出問題所在?


hshua (hshua)

學校 : 新北市立林口高級中學
編號 : 52506
來源 : [125.228.147.181]
最後登入時間 :
2024-11-10 13:26:19
a468. 12439 - February 29 -- UVa12439 | From: [220.133.124.235] | 發表日期 : 2019-08-25 16:02

沒有測資,實在找不出來,高手可否指教,錯在哪?

#-------------------------------------------------------------------------------

dict={'January':'1','February':'2','March':'3','April':'4','May':'5','June':'6','July':'7','August':'8','September':'9','October':'10','November':'11','December':'12'}
def YEAR(x):
if((x%4==0 and x%100!=0) or x%400==0): return True

n = int(input())
for Case in range(n):
    s1 = input().split()
    s1[1] = s1[1].replace(',','')
    s1[0] = dict[s1[0]]
    s1 = list(map(int,s1))

    s2 = input().split()
    s2[1] = s2[1].replace(',','')
    s2[0] = dict[s2[0]]
    s2 = list(map(int,s2))

    y1 = s1[2] 
    while(y1<=s2[2]): #find the 1st leap year
        if(YEAR(y1)==True): break
        else: y1+=1

    Yn = 0
    if(y1>s2[2]): Yn=0 #no leap years
    else:
        Yn = (s2[2]-y1)//4 + 1 #cal. how many leap years
        #print('@@@ ',y1,Yn)
        if(s1[2]==y1): #if 1st year is leap
            d1 = y1*10000 + s1[0]*100 + s1[1]
            d0 = y1*10000 + 229
            if(d1>d0): Yn-=1
            #print('###',d1,d0,Yn)
        if(YEAR(s2[2])): #if last year is leap
            d2 = s2[2]*10000 + s2[0]*100 + s2[1]
            d0 = s2[2]*10000 + 229
            if(d2<d0): Yn-=1
            #print('###',d1,d0,Yn)
    print('Case %d: %d' %(Case+1,Yn))

 

 

 

 

 
ZeroJudge Forum