-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.cpp
More file actions
28 lines (22 loc) · 719 Bytes
/
Copy path19.cpp
File metadata and controls
28 lines (22 loc) · 719 Bytes
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
#include <iostream>
using namespace std;
#define SUNDAY 0x0
#define TUESDAY 0x2
#define LEAP(YEAR) (YEAR % 100 == 0 ? YEAR % 400 == 0 : YEAR % 4 == 0)
#define DAYS(MONTH, YEAR) MONTH == 2 ? (LEAP(YEAR) ? 29 : 28) : days[MONTH]
#define FIRST_OF_NEXT_MONTH(N_DAYS, TODAY) (N_DAYS == 28 ? TODAY : (TODAY + (N_DAYS % 29) + 1) % 7)
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
int today = TUESDAY, count = 0, days_in_month;
for (int year = 1901; year < 2001; year++)
{
for (int month = 1; month <= 12; month++)
{
days_in_month = DAYS(month, year);
today = FIRST_OF_NEXT_MONTH(days_in_month, today);
count += (today == SUNDAY);
}
}
cout << count << endl;
}