Write a program that reads a sequence of dates, and for each one prints the corresponding weekday, or prints that the date is not correct according to the Gregorian calendar.
Implement the functions
bool is_leap_year(int year);
bool is_correct_date(int day, int month, int year);
string weekday(int day, int month, int year);
Given a year @y@, @is_leap_year(y)@ tells if @y@ is a leap year or
not. Given a date defined with @d@, @m@ and @y@, @is_correct_date(d, m,
y)@ tells if the date is correct or not according to the Gregorian
calendar. Given a correct date defined with @d@, @m@ and @y@,
@weekday(d, m, y)@ returns the corresponding weekday (that is,
“Monday”, “Tuesday”, …).
To know the weekday, use the congruence of Zeller: Given a date defined by the triple , where is the day, is the month, and is the year,
Subtract two units to the month , and if the result is zero or less, add 12 to the month and subtract a unit to the year. Call the new month and call the new year.
Compute the century (the first two digits of the year) from the year .
Compute the year inside the century (the two last digits of the year) from the year .
Compute
Finally, modulo 7 give us the desired result: 0 represents Sunday, 1 represents Monday, 2 represents Tuesday...
You can find the rule about leap years in the exercise
problem://problemsjutge.org:problems/p1/jpetit/traspas-elemental
.
For the functions @is_leap_year()@ and @is_correct_date()@, the value of the year is always between 1800 and 9999 (both included). For the function @weekday()@, the given date is always correct w.r.t. the function @is_correct_date()@.
Each date of the input is composed by three integers, corresponding respectively to the day, the month and the year. All the years are between 1800 and 9999.
For each date of the input, print in a line the corresponding weekday
(“Monday”, …, “Sunday”) if it is a correct
date according to the Gregorian calendar, or
“Incorrect Date” if it is not.
Jordi Petit (en: Carlos Molina)
© Jutge.org, 2006–2025.
Input
30 11 1971 6 4 1971 4 8 2001 29 2 2001 32 11 2005 30 11 2004 6 9 1901
Output
Tuesday Tuesday Saturday Incorrect Date Incorrect Date Tuesday Friday