萌新跪求哪位大佬能帮忙看一下,样例都过不去嘤嘤嘤

P1202 [USACO1.1] 黑色星期五Friday the Thirteenth

#### 你可以先搞个数组记录,如: ```cpp month[15]={0,31,28,31,30,31,30,31,31,30,31,30,31} ``` 然后在循环年的那层循环里面判断是否为闰年,是闰年就在第二月加1,参考代码如下: ```cpp #include<bits/stdc++.h> using namespace std; bool check(int a) { if(a%4==0 && a%100!=0 || a%400==0) { return true; } else return false; } int month[15]= {0,31,28,31,30,31,30,31,31,30,31,30,31},sumday; int ans[8]; int main() { int n; cin>>n; for(int i=1900; i<=1900+n-1; i++) { //year bool flag=check(i); for(int j=1;j<=12;j++) { //month int E=0; if(j==2 && flag==true) E=1; for(int k=1;k<=month[j]+E;k++) { sumday++; //总天数 if(k==13) { ans[sumday%7]++; } } } } cout<<ans[6]<<' '<<ans[0]<<' '<<ans[1]<<' '<<ans[2]<<' '<<ans[3]<<' '<<ans[4]<<' '<<ans[5]<<endl; return 0; } ```
by inaoui @ 2020-10-23 16:56:47


|