Calendar Quiz: Super Quiz Bee is a famous quiz Competition that tests students on a wide variety of academic subjects. This week’s participants were kids of age 12 to 15 and the quiz questions were based on Gregorian calendar.
In the first round of the competition, the Host of the event told the participants that it was Monday on the date 01/01/2001. Later he questioned each one of the participant what would be the day on the 1st January, giving them a particular year. Write a program to help the Host validate the answers given by the participants.
Input Format:
The first line contains an integer that corresponds to a year.
Output Format:
Output the day on the 1st January of that given year.
Refer sample input and output for formatting specifications.
Sample Input 1:
1994
Sample Output 1:
Saturday
Sample Input 2:
2014
Sample Output 2:
Wednesday
Solution
ref_year = 1900
year = 0
leap = 0
diff = 0
total_days = 0
day = 0
year = int(input())
diff = year - ref_year
while(ref_year < year):
if(ref_year % 100 == 0):
if(ref_year % 400 == 0):
leap += 1
else:
if(ref_year % 4 == 0):
leap += 1
ref_year += 1
total_days = (diff - leap) * 365 + leap * 366
day = total_days % 7
if day == 0:
print("Monday")
elif day == 1:
print("Tuesday")
elif day == 2:
print("Wednesday")
elif day == 3:
print("Thursday")
elif day == 4:
print("Friday")
elif day == 5:
print("Saturday")
elif day == 6:
print("Sunday")
#include<iostream>
using namespace std;
int main()
{
int ref_year = 1900, year, leap = 0, diff, total_days = 0, day = 0;
cin >> year;
diff = year - ref_year;
while(ref_year < year)
{
if(ref_year % 100 == 0)
{
if(ref_year % 400 == 0)
{
leap++;
}
}
else
{
if(ref_year % 4 == 0)
{
leap++;
}
}
ref_year++;
}
total_days = (diff - leap) * 365 + leap * 366;
day = total_days % 7;
switch(day)
{
case 0: printf("Monday\n");
break;
case 1: printf("Tuesday\n");
break;
case 2: printf("Wednesday\n");
break;
case 3: printf("Thursday\n");
break;
case 4: printf("Friday\n");
break;
case 5: printf("Saturday\n");
break;
case 6: printf("Sunday\n");
break;
}
return 0;
}
Happy Learning – If you require any further information, feel free to contact me.