-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriday.cpp
More file actions
72 lines (65 loc) · 1.46 KB
/
Copy pathfriday.cpp
File metadata and controls
72 lines (65 loc) · 1.46 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
ID: dswei191
LANG: C++
TASK: friday
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int week[7] = {0,0,0,0,0,0,0};
int leapMonthDays[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int noLeapMonthDays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
ofstream fout("friday.out");
ifstream fin("friday.in");
bool isLeap(int year){
if(year % 100 == 0){
if(year % 400 == 0){
return true;
}else{
return false;
}
}else{
if(year % 4 == 0){
return true;
}else{
return false;
}
}
}
int loopMonth(int year, int month, int startWeekDay){
int* monthDays;
if(month == 1 && isLeap(year)){
monthDays = leapMonthDays;
}else{
monthDays = noLeapMonthDays;
}
int idx = (startWeekDay + (13 % 7)) % 7;
week[idx] += 1;
int nxtIdx = (startWeekDay + (monthDays[month] % 7)) % 7;
// cout << nxtIdx <<endl;
return nxtIdx;
}
int loopYear(int year, int startWeekDay){
for(int i = 0; i < 12; i++){
startWeekDay = loopMonth(year, i, startWeekDay);
}
return startWeekDay;
}
int main(){
int n;
fin >> n;
int year, startWeekDay = 1;
for(int i = 0; i < n; i++){
year = 1900 + i;
startWeekDay = loopYear(year, startWeekDay);
}
for(int i = 0; i < 7; i++){
fout<< week[i];
if(i != 6){
fout << ' ';
}
}
fout << endl;
return 0;
}