We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTm_days=[0,31,28,31,30,31,30,31,31,30,31,30,31]defis_leap(y):ify%100==0:return(Trueify%400==0elseFalse)ify%4==0:return(True)else:return(False)defno_of_leapyear(y):ify[0]>2000:return(100//4+(y[0]-2000)//4-(y[0]-2000)//100+(y[0]-2000)//400-(1ifis_leap(y[0])and(y[1]==1or(y[1]==2andy[2]<=28))else0))else:return((y[0]-1900)//4-(1ifis_leap(y[0])and(y[1]==1or(y[1]==2andy[2]<=28))else0))fora0inrange(int(input())):y1,y2=list(map(int,input().split())),list(map(int,input().split()))ifnoty1[2]==1:ify1[1]==12:y1=[y1[0]+1,1,1]else:y1=[y1[0],y1[1]+1,1]diffy1=365*(y1[0]-1900)+sum(m_days[:y1[1]])+(y1[2]-1)+no_of_leapyear(y1)sundays=1ifdiffy1%7==6else0#print(diffy1 % 7)diffy1=6-diffy1%7# diffs to sundayify1[0]==y2[0]:ify1[1]>y2[1]:print(0)continueelify1[1]==y2[1]:print(sundays)continueelify1[0]>y2[0]:print(sundays)continue#print(diffy1)whilenoty1[0]>y2[0]andnot(y1[0]==y2[0]andy1[1]>=y2[1]):#print(y1)d=(m_days[y1[1]]+1)ify1[1]==2andis_leap(y1[0])elsem_days[y1[1]]ifd%7==diffy1:sundays=sundays+1diffy1=(diffy1-d%7)ifd%7<=diffy1else(7-(d%7)+diffy1)#print(y1, diffy1)ify1[1]==12:y1=[y1[0]+1,1,1]else:y1=[y1[0],y1[1]+1,1]print(sundays)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #19: Counting Sundays
You are viewing a single comment's thread. Return to all comments →
100%