-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCODECHEF_FLOW015.c
85 lines (83 loc) · 1018 Bytes
/
CODECHEF_FLOW015.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//CodeChef Problem : Gregorian Calender (Beginner)
//Problem Code : FLOW015
//Author : PIYUSH
#include<stdio.h>
#include<stdlib.h>
int leap(int);
int prev(int);
int next(int);
int main()
{
int t,y,c;
scanf("%d",&t);
while(t--)
{
scanf("%d",&y);
if(y>2001)
{
c=next(y);
c=c%7;
}
else
{
c=prev(y);
c=c/7;
}
if(c==1)
printf("monday\n");
else if(c==2)
printf("tuesday\n");
else if(c==3)
printf("wednesday\n");
else if(c==4)
printf("thrusday\n");
else if(c==5)
printf("friday\n");
else if(c==6)
printf("saturday\n");
else
printf("sunday\n");
}
return 0;
}
int leap(int y)
{
if(y%4==0)
{
if(y%100==0)
{
if(y%400==0)
return 1;
else
return 0;
}
else
return 1;
}
else
return 0;
}
int next(int y)
{
if(y == 2001)
return 1;
else
{
if(leap(y)==1)
return 2+next(--y);
else
return 1+next(--y);
}
}
int prev(int y)
{
if(y == 2001)
return 1;
else
{
if(leap(y)==1)
return 2+prev(++y);
else
return 1+prev(++y);
}
}