洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
黑色星期五
难度:☆
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
//Mystery_Sky
//
int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ans[8], N, date;
int main() {
scanf("%d", &N);
bool flag_1 = false, flag_2 = false;
N = 1900 + N - 1;
for(int i = 1900; i <= N; i++) {
flag_1 = flag_2 = false;
if(i % 100 == 0) flag_2 = true;
if(flag_2 && i % 400 == 0) flag_1 = true;
else if(!flag_2 && i % 4 == 0) flag_1 = true;
if(flag_1) day[2] = 29;
for(int j = 1; j <= 12; j++) {
for(int k = 1; k <= day[j]; k++) {
date++;
date %= 7;
if(k == 13)
ans[date]++;
}
}
day[2] = 28;
}
printf("%d %d ", ans[6], ans[0]);
for(int i = 1; i <= 5; i++) printf("%d ", ans[i]);
return 0;
}
唯愿,青春不辜负梦想,未来星辰闪耀