-
Notifications
You must be signed in to change notification settings - Fork 0
/
friday.c
59 lines (50 loc) · 1.11 KB
/
friday.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
ID: talos
LANG: C
PROG: friday
*/
#include <stdio.h>
#define INPUT "friday.in"
#define OUTPUT "friday.out"
#define RETURN_SUCCESS 0
int main (void)
{
/* definitions */
unsigned short int n , year , leap , day , result[7] ;
int c , c2 ;
FILE *in , *out ;
/* initialization */
int m[13] = { 0 , 31, 28 , 31 , 30 , 31 , 30 ,
31 , 31 , 30 , 31 , 30 ,31 };
for (c=0;c<8;c++)
{
result[c]= 0 ;
}
/* open file and read the number*/
in = fopen (INPUT , "r");
fscanf (in , "%d" , &n);
fclose (in);
year = 1900 ; day=0 ; /* Sunday 31-12-1899 */
for (c2 = year ; c2 < year+n ; c2++)
{
leap = c2%4 == 0 && c2%100 !=0 || c2%400 == 0 ;
m[2]+=leap ;
for (c=1;c<13;c++)
{
day=(day+13)%7 ;
result[day]++ ;
day= (day+m[c]-13)%7 ;
}
m[2]=28 ; /* restore february days*/
}
/* write data to output file */
out = fopen (OUTPUT , "w");
fprintf( out ,"%d " , result[6]);
for (c=0;c<5;c++)
{
fprintf( out , "%d " , result[c]);
}
fprintf( out ,"%d\n" , result[5]);
fflush(out) ; fclose (out);
return (RETURN_SUCCESS);
}