From ad4e2420e822b8a115aac6124307b89447578782 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Mon, 16 Apr 2018 19:06:32 +0800 Subject: 1.2~1.5 --- 1.2/friday.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 1.2/friday.c (limited to '1.2/friday.c') diff --git a/1.2/friday.c b/1.2/friday.c new file mode 100644 index 0000000..c0b2ceb --- /dev/null +++ b/1.2/friday.c @@ -0,0 +1,48 @@ +/* +ID: mytbk921 +LANG: C +TASK: friday +*/ + +#include + +int isleap(int year) +{ + if (year%4==0 && (year%100!=0 || year%400==0)) + return 1; + else + return 0; +} + +const int DaysOfMonth[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; + +int main() +{ + int n; //years eclipsed + int year; + int nDays[7]={0}; //number of Sat. to Fri. + int wDay=2+12; //the week day,1900.01.01 is Monday(2) + int i; + FILE *fin=fopen("friday.in","r"); + FILE *fout=fopen("friday.out","w"); + + fscanf(fin,"%d",&n); + for (year=1900;year<1900+n;year++){ + int type=isleap(year); + for (i=0;i<12;i++){ + wDay%=7; + nDays[wDay]++; + wDay+=DaysOfMonth[type][i]; + } + } + for (i=0;i<7;i++){ + if (i) + fputc(' ',fout); + fprintf(fout,"%d",nDays[i]); + } + fputc('\n',fout); + fclose(fin); + fclose(fout); + return 0; +} + -- cgit v1.2.3