模拟 当然也是简单的数学问题啦 注意一下输出格式是从周六开始的就可以了
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned long long ull; 5 6 namespace io { 7 const int SIZE = 1e7 + 10; 8 char inbuff[SIZE]; 9 char *l, *r; 10 inline void init() { 11 l = inbuff; 12 r = inbuff + fread(inbuff, 1, SIZE, stdin); 13 } 14 inline char gc() { 15 if (l == r) init(); 16 return (l != r) ? *(l++) : EOF; 17 } 18 void read(int &x) { 19 x = 0; char ch = gc(); 20 while(!isdigit(ch)) ch = gc(); 21 while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc(); 22 } 23 } using io::read; 24 25 int main(){ 26 int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 27 int ans[8]; 28 memset(ans, 0, sizeof(ans)); 29 int N; 30 cin>>N; 31 int days = 0; 32 bool flag; 33 int tmp; 34 for (int i = 1900; i < 1900 + N; i++){ 35 flag = false; 36 if (!(i % 4) && (i % 100) || !(i % 400)) flag = true; 37 for (int j = 1; j <= 12; j++){ 38 tmp = 0; 39 if (flag && j == 2) tmp = 1; 40 for (int k = 1; k <= month[j] + tmp; k++){ 41 days++; 42 if (k == 13) 43 ans[days % 7]++; 44 } 45 } 46 } 47 printf("%d %d %d %d %d %d %d\n", ans[6], ans[0], ans[1], ans[2], ans[3], ans[4], ans[5]); 48 return 0; 49 }