USACO Section 1.1: Friday the Thirteenth

 1 /*

 2 ID: leetcod3

 3 PROG: friday

 4 LANG: C++

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 #include <cstdio>

19 #include <cstdlib>

20 #include <limits>

21 #include <stack>

22 

23 using namespace std;

24 

25 ofstream fout ("friday.out");

26 ifstream fin ("friday.in");

27 

28 bool leap(int year) {

29     return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;

30 }

31 

32 int main() {

33     int N;

34     fin >> N;

35     int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

36     int day = 0;

37     vector<int> days(7);

38     for (int i = 1900; i < 1900 + N; i++) {

39         for (int j = 0; j < 12; j++) {

40             days[(day + 12) % 7]++;

41             if (j == 1) day += (leap(i)? 29 : 28);

42             else day += month[j];

43         }

44     }

45     fout << days[5] << " " << days[6] << " ";

46     for (int i = 0; i < 4; i++) fout << days[i] << " ";

47     fout << days[4] << endl;

48     return 0;

49 }

 

你可能感兴趣的:(USACO)