-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path019.py
More file actions
50 lines (40 loc) · 1.08 KB
/
019.py
File metadata and controls
50 lines (40 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def zeller_congruence(year, month, day):
if month == 1:
month = 13
year -= 1
elif month == 2:
month = 14
year -= 1
K = year % 100
J = year // 100
return (day + (13 * (month + 1) // 5) + K + (K // 4) + (J // 4) + 5 * J) % 7
def compare_dates(date1, date2):
Y1, M1, D1 = date1[0], date1[1], date1[2]
Y2, M2, D2 = date2[0], date2[1], date2[2]
if Y1 < Y2:
return True
elif Y1 == Y2:
return M1 <= M2
else:
return False
def find_sundays(date1, date2):
Y1, M1, D1 = date1[0], date1[1], date1[2]
counter = 0
a, b = Y1, M1
if M1 < 12 and D1 > 1:
b += 1
elif M1 == 12 and D1 > 1:
b, a = 1, a + 1
while compare_dates([a, b, 1], date2):
if zeller_congruence(a, b, 1) == 1:
counter += 1
if b == 12:
a, b = a + 1, 1
else:
b += 1
return counter
T = int(input())
for _ in range(T):
date1 = list(map(int, input().split()))
date2 = list(map(int, input().split()))
print(find_sundays(date1, date2))