Posted on 2009-03-05 11:39
superman 阅读(149)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 bool isLeapYear(int y)
6 {
7 return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
8 }
9
10 int theAmountOfDaysInTheMonth(int y, int m)
11 {
12 switch (m)
13 {
14 case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 :
15 return 31;
16 case 4 : case 6 : case 9 : case 11 :
17 return 30;
18 case 2 :
19 return isLeapYear(y) ? 29 : 28;
20 }
21 }
22
23 int main()
24 {
25 freopen("friday.in", "r", stdin);
26 freopen("friday.out", "w", stdout);
27
28 int n;
29
30 cin >> n;
31
32 int y = 1900, m = 1, d = 1, dayOfWeek = 0, cnt[7] = { 0 };
33 for (y = 1900; y <= 1900 + n - 1; y++)
34 {
35 for (m = 1; m <= 12; m++)
36 for (d = 1; d <= theAmountOfDaysInTheMonth(y, m); d++)
37 {
38 if (d == 13)
39 cnt[dayOfWeek]++;
40 dayOfWeek = (dayOfWeek + 1) % 7;
41 }
42 }
43
44 cout << cnt[5] << ' ' << cnt[6] << ' '
45 << cnt[0] << ' ' << cnt[1] << ' '
46 << cnt[2] << ' ' << cnt[3] << ' '
47 << cnt[4] << endl;
48
49 return 0;
50 }
51