-
Notifications
You must be signed in to change notification settings - Fork 0
/
p19.cpp
67 lines (61 loc) · 1.03 KB
/
p19.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
int month(int m,int y)
{
switch(m)
{
case 1:
return 3;
case 2:
if (y%4==0)
return 1;
else
return 0;
case 3:
return 3;
case 4:
return 2;
case 5:
return 3;
case 6:
return 2;
case 7:
return 3;
case 8:
return 3;
case 9:
return 2;
case 10:
return 3;
case 11:
return 2;
case 12:
return 3;
default:
return -1;
}
}
int solve()
{
int d = 1;//day of week
int m;//Jan
int y;
int count = 0;
for(y=1900; y <= 2000; y++)
{
for (m = 1; m <= 12; m++)
{
d %= 7;
if (d == 0 && y >= 1901)
count++;
d += month(m,y);
}
}
cout << "Num Sundays:" << count << endl;
return count;
}
int main(int argc, char **argv)
{
solve();
return 0;
}