Problem Description
According to Gregorian Calendar, it was Monday on the date 01/01/2001. If any year is input,
Write a program to display what is the day on the 1st January of this year.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer year.
Output
Display the day on the 1st January of that year in lowercase letter.
Constraints
1 <=T <=1000
1900<=A,B,C<=2500CODING ARENA
#include <stdio.h>
#include <math.h>
int main()
{
int t,year,i,count;
scanf("%d",&t);
while(t--)
{count=1;
scanf("%d",&year);
for(i=1901;i<=year;i++)
{
if((i-1)%400==0)
count+=2;
else if((i-1)%100!=0 && (i-1)%4==0)
count+=2;
else
count+=1;
}
if(count%7==0)
printf("sunday\n");
else if(count%7==1)
printf("monday\n");
else if(count%7==2)
printf("tuesday\n");
else if(count%7==3)
printf("wednesday\n");
else if(count%7==4)
printf("thursday\n");
else if(count%7==5)
printf("friday\n");
else if(count%7==6)
printf("saturday\n");
}
return 0;
}
Test Case 1
Input (stdin)3 1994 1991 2014
Expected Outputsaturday tuesday wednesday
Test Case 2
Input (stdin)2 2016 2017
Expected Outputfriday sunday
No comments:
Post a Comment