friday

  之前把1900当成1990死活做不出,第 一章的最后才发现了这个问题,还是在队友的指导下发现的,囧!!!

  这题的考查的是7以内的模运算,第i个月的星期数和天数记为week[i],month[i]

则week[i]=(week[i-1]+month[i-1])%7。

#include<cstdio> #include<iostream> #include<string.h> using namespace std; int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int ans[7]; int main(){ freopen("friday.in","r",stdin); freopen("friday.out","w",stdout); int n; cin>>n; int i; int cur=13%7; memset(ans,0,sizeof(ans)); for(i=1900;i<1900+n;i++){ ans[cur]++; cur=(cur+day[1])%7; ans[cur]++; if( (i%100) && (i%4==0) || i%400==0 )cur++; cur=(cur+day[2])%7; int j; for(j=3;j<=12;j++){ ans[cur]++; cur=(cur+day[j])%7; } } for(i=6;i!=5; i++,i%=7 )cout<<ans[i]<<' '; cout<<ans[i]<<endl; return 0; }

你可能感兴趣的:(friday)