-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem19.cpp
More file actions
53 lines (47 loc) · 1.04 KB
/
Problem19.cpp
File metadata and controls
53 lines (47 loc) · 1.04 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
51
52
53
#include <iostream>
int isLeapYear(int year){
if (year % 400 == 0)
{
return 1;
}
else if (year % 4 == 0 && year % 100 != 0)
{
return 1;
}
else
{
return 0;
}
}
int main(){
int day = 1, year = 1900, sunday = 0;
unsigned long count = 0;
int n[] = {3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3}; //the odd days for each month
++year;//starting from 1901
day = 2; //for 1901
while (year < 2001)
{
for (size_t i = 0; i < 12; i++)
{
count = count + ((day == 0) ? 1 : 0);
if (isLeapYear(year))
{
if (i == 1)
{
day = (day + n[i] + 1) % 7;
}
else
{
day = (day + n[i]) % 7;
}
}
else
{
day = (day + n[i]) % 7;
}
}
year++;
}
std::cout << count << std::endl;
return 0;
}