1.1Friday the Thirteenth+简单模拟

n只有400,,所以可以直接暴力模拟。 因为一个小问题卡了很久。。。。。。

代码如下:

/*ID: 15674811LANG: C++TASK: friday*/;bool is_leap(int year){if(year%4==0&&year%100!=0)return 1;if(year%400==0)return 1;return 0;}int main(){int day[15]={31,31,28,31,30,31,30,31,31,30,31,30,31};ofstream fout(“friday.out”);ifstream fin(“friday.in”);int n;int week[10];while(fin>>n){int tmp=3; //记录前面那个月的13号是星期几memset(week,0,sizeof(week));for(int year=1900;year<1900+n;year++){for(int j=1;j<=12;j++){int d;d=day[j-1];if(j==3&&is_leap(year))d=29;int t=(d%7+tmp)-((d%7+tmp)/7)*7;if(t==0)t+=7;week[t]++;tmp=t;}}fout<<week[6]<<” “<<week[7]<<” “;for(int i=1;i<5;i++)fout<<week[i]<<” “;fout<<week[5]<<endl;} return 0;}

不要再以任何人说你,因为你不是为任何人而活,你只为自己而活,

1.1Friday the Thirteenth+简单模拟

相关文章:

你感兴趣的文章:

标签云: