Title Requirements:
Enter the code:
#include <iostream> #include <stdio.h> #include <cstdlib>using namespace Std;int month[13]= { 0,31,28,31,30,31,30,31,31,30,31,30,31};int ans[8]= {0};int n,end;void work (int n) {int y,m,d,i; int w=1; y=1900; end=y+n-1; m=d=1; while (y!=end| | m!=12| | D!=31)//To end year December 31 exit Loop {if (d==month[m]+1)//To end of month, replace January {d=1; m++; } if (m==13)//means to December, to the next year {y++; M=1; } if ((y%100!=0&&y%4==0) | | | y%400==0)//Leap year of February {month[2]=29; } else {month[2]=28; } if (d==13)//13 number {ans[w]++;//13 number of times in the Week plus 1} w + +; W = (w-1)% 7 + 1;//indicates weeks D + +; } cout<<ans[6]<< "" <<ans[7]<< ""; for (I=1; i<=4; i++) {cout<<ans[i]<< ""; } Cout<<ans[5]<<endl;} int main () {//freopen ("friday.in", "R", stdin); FreopEn ("Friday.out", "w", stdout); cin>>n; Work (n); Fclose (stdin);//Close File//fclose (stdout);//close file return 0;}
Operation Result:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
OJ Brush Question---1.1.3 Friday the thirteenth Black Friday