- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem019.cpp
More file actions
Latest commit
23 lines (21 loc) · 540 Bytes
/
Copy pathproblem019.cpp
File metadata and controls
23 lines (21 loc) · 540 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
// Originally posted by Tomohiko Sakamoto on the comp.lang.c Usenet newsgroup.
intdayOfWeek(int y, int m, int d)
{
int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
y -= m < 3;
return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}
intmain()
{
int ans = 0;
for (int y = 1901; y <= 2000; ++y) {
for (int m = 1; m <= 12; ++m) {
if (dayOfWeek(y, m, 1) == 0) {
++ans;
}
}
}
std::cout << "Answer: " << ans << '\n';
return0;
}