CSP201509-2: date calculation, csp201509-2 Calculation
Introduction:CSP (http://www.cspro.org/lead/application/ccf/login.jsp) is a "Computer vocational qualification certification" examination initiated by CCF, perform capability certification for professionals in computer software development, software testing, information management, and other fields. The subjects of certification are those who are engaged in or will be engaged in IT professional technical and technical management personnel, as well as review subjects for university recruitment and postgraduate students.
Given a year y and an integer d, how many days is the d day of the year?
Note that there are 29 days in March February of the leap year. One of the following conditions is a leap year:
1) The year is an integer multiple of 4, not an integer multiple of 100;
2) The year is an integer multiple of 400.
The first line of the input contains an integer y, indicating the year. The year ranges from 1900 to 2015 (including 1900 and 2015 ).
The second row of the input contains an integer d between 1 and 365.
Two rows are output, each with an integer representing the month and date of the answer, respectively.
- Sample Input
2015
80
- Sample output
3
21
- Sample Input
2000
40
- Sample output
2
9
- Source code
# Include <stdio. h> Int main (void) { Int days [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31 }; Int y; // year Int d; // integer Scanf ("% d", & y ); Scanf ("% d", & d ); If (y % 4 = 0 & y % 100! = 0) | y % 400 = 0) // It is a leap year. { Days [1] = 29; } For (int I = 0; I <12; I ++) { If (d <= days [I]) { Int month = I + 1; Int day = d; Printf ("% d \ n", month ); Printf ("% d \ n", day ); Break; } Else { D-= days [I]; } } Return 0; } |