-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler19.cpp
91 lines (80 loc) · 1.73 KB
/
Euler19.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <unistd.h>
#include <fstream>
using namespace std;
class Date{
public:
Date(){
year = 1900;
month = 0;
day_num = 1;
total_day_count = 1;
day_names = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
days_per_month = {31,28,31,30,31,30,31,31,30,31,30,31};
}
string get_day_name() const{
return day_names[total_day_count%7];
}
void increment_day(){
day_num++;
total_day_count++;
if(day_num > days_per_month[month]){
month += 1;
day_num = 1;
if(month >= 12){
month = 0;
year += 1;
if(year%4 == 0){
if(year%100 == 0 && year%400 != 0){
days_per_month[1]=28;
return;
}
days_per_month[1]=29;
}
else{
days_per_month[1]=28;
}
}
}
}
int get_year() const{
return year;
}
int get_month() const {
return month;
}
string get_month_name() const{
vector<string> month_names = {"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};
return month_names[month];
}
int get_day_num() const{
return day_num;
}
private:
int year;
int month;
int day_num;
vector<int> days_per_month;
vector<string> day_names;
int total_day_count;
};
ostream& operator<<(ostream& os, const Date& d){
os << d.get_day_name() << " " << d.get_day_num() << ", " << d.get_month_name() << " " << d.get_year()<<endl;
return os;
}
int main(){
Date d;
int count = 0;
while(d.get_year() != 2000 || d.get_month() != 11 || d.get_day_num() != 31){
if(d.get_day_name() == "Sunday" && d.get_day_num() == 1 && d.get_year() >= 1901){
count ++;
}
cout<<d;
d.increment_day();
}
cout<<count<<endl;
}