60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
/** 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 "0.hpp"
|
|
|
|
#define _ori 1901
|
|
#define _base 1900
|
|
#define _end 2000
|
|
#define _moon 1
|
|
#define _day 0
|
|
|
|
//int month[13] = {1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
int month[13] = {0, 3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3};
|
|
int year[2] = {1, 2};
|
|
string day[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
|
|
|
int leap(int a)
|
|
{
|
|
if(a % 100 == 0) {
|
|
if(a % 400 == 0) return 1;
|
|
else return 0;
|
|
}
|
|
else {
|
|
if(a % 4 == 0) return 1;
|
|
else return 0;
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int count = 0;
|
|
int sum = 1;
|
|
int yearsum;
|
|
for(int i = _ori; i <= _end; i++) { // loop of year
|
|
sum += year[leap(i - 1)];
|
|
yearsum = 0;
|
|
cout << i << '\t';
|
|
//for(int j = 2; j <= _moon; j++) // loop of month
|
|
//yearsum += month[j - 1];
|
|
//if(_moon > 2 && leap(i)) yearsum += month[0];
|
|
for(int j = 0; j < 12; j++) {
|
|
yearsum += month[j];
|
|
if(j == 2 && leap(i)) yearsum++;
|
|
if((sum + yearsum) % 7 == _day) count++;
|
|
cout << (sum + yearsum) % 7 << " ";
|
|
}
|
|
|
|
cout << '\t' << count;
|
|
cout << endl;
|
|
//for(int k = 0; k < month[_moon]; k++) // loop of date
|
|
//if((sum + k + yearsum) % 7 == _day) count++;
|
|
|
|
//cout << i << " " << (sum + yearsum) % 7 << endl;
|
|
}
|
|
|
|
cout << count << endl;
|
|
|
|
return 0;
|
|
}
|