-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp19.cpp
More file actions
37 lines (34 loc) · 835 Bytes
/
Copy pathp19.cpp
File metadata and controls
37 lines (34 loc) · 835 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
29
30
31
32
33
34
35
36
37
/**
* 1 Jan 1900 was a Monday.
*
* How many Sundays fell on the first of the month during the twentieth
* century (1 Jan 1901 to 31 Dec 2000)?
*/
#include <iostream>
#include "euler/datetime.hpp"
#include "euler.h"
BEGIN_PROBLEM(19, solve_problem_19)
PROBLEM_TITLE("Counting Sundays")
PROBLEM_ANSWER("171")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("")
PROBLEM_SPACE_COMPLEXITY("")
PROBLEM_KEYWORDS("calendar")
END_PROBLEM()
static void solve_problem_19()
{
const int sunday = euler::datenum(1899, 12, 31);
int num_sundays = 0;
for (int year = 1901; year <= 2000; year++)
{
for (int month = 1; month <= 12; month++)
{
if ((euler::datenum(year, month, 1) - sunday) % 7 == 0)
{
num_sundays++;
}
}
}
std::cout << num_sundays << std::endl;
}