Description:
We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004,218 0 and 2400 are leap. Years 2004,218 1 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today's agreement about dating.
Input:
There is one single line contains the day number D, month name M and Year Number y (1000 ≤ y ≤ 3000). The month name is the corresponding English name starting from the capital letter.
Output:
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.
Sample input:
9 October 2001
14 October 2001
Sample output:
Tuesday
Sunday
Tip:
Month and week name in input/output:
January, February, March, limit L, May, June, July, August, September, October, November, December
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Code:
# Include <iostream> using namespace STD; # include <string. h> int main () {char month [13] [10] = {"", "January", "February", "March", "Limit L", "may ", "June", "July", "August", "September", "October", "November", "December "}; char week [7] [10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "}; int dofm [13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31}; int y, M, D; int Cy = 2014, Cm = 7, Cd = 24, Cw = 4; // replace this with the actual situation today: Char mon [10]; int I, count1, count2, dofweek; while (CIN> D> mon> Y) {for (I = 1; I <= 12; I ++) {If (strcmp (month [I], mon) = 0) {M = I; break ;}// cout <m <Endl; if (Y> Cy | (y = Cy & M> CM) | (y = Cy & M = CM & D> Cd )) // enter the year, month, and day after today {// calculate the number of days for the Cy cm CD to depart from CY 01 01; count1 = 0; for (I = 1; I <cm; I ++) {count1 + = dofm [I];} If (cm> 2 & (CY % 4 = 0 & Cy % 100! = 0) | Cy % 400 = 0) {count1 + = 1;} count1 + = Cd; // calculate the number of days from Y m d to cy 01 count2 = 0; for (I = Cy; I <Y; I ++) {If (I % 4 = 0 & I % 100! = 0) | I % 400 = 0) {count2 + = 366;} else {count2 + = 365 ;}for (I = 1; I <m; I ++) {count2 + = dofm [I];} If (M> 2 & (Y % 4 = 0 & Y % 100! = 0) | Y % 400 = 0) {count2 + = 1;} count2 + = D; // cout <count2-count1 <Endl; dofweek = (count2-count1) % 7 + CW) % 7; cout <week [dofweek] <Endl ;} else // enter the year, month, and day before today {// calculate the number of days from Y m d to Y 01 01 count1 = 0; for (I = 1; I <m; I ++) {count1 + = dofm [I];} If (M> 2 & (Y % 4 = 0 & Y % 100! = 0) | Y % 400 = 0) {count1 + = 1;} count1 + = D; // calculate the number of days from CY cm CD to Y 01 count2 = 0; for (I = y; I <Cy; I ++) {If (I % 4 = 0 & I % 100! = 0) | I % 400 = 0) {count2 + = 366;} else {count2 + = 365 ;}} for (I = 1; I <cm; I ++) {count2 + = dofm [I] ;}if (cm> 2 & (CY % 4 = 0 & Cy % 100! = 0) | Cy % 400 = 0) {count2 + = 1;} count2 + = Cd; // cout <count2-count1 <Endl; dofweek = (cw-(count2-count1) % 7) + 7) % 7; cout <week [dofweek] <Endl ;}} return 0 ;} /*************************************** * *********************** problem: 1043 User: [email protected] language: C ++ result: accepted time: 0 MS memory: 1520 kb ************************************** **************************/
View code