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
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int weekday[7];
int get(int year, int m) { if (m != 2) return months[m]; if (year % 100 && year % 4 == 0 || year % 400 == 0) return 29; return 28; }
int main() { int n; cin >> n;
int week = 0; int year = 1900, month = 1, day = 1; while (year < 1900 + n) { if (day == 13) weekday[week] ++ ; week = (week + 1) % 7; day ++ ; if (get(year, month) < day) month ++, day = 1; if (month > 12) month = 1, year ++ ; }
for (int i = 5, j = 0; j < 7; i = (i + 1) % 7, j ++ ) cout << weekday[i] << ' '; cout << endl;
return 0; }
|