CSP201509-2: date calculation, csp201509-2 Calculation

Source: Internet
Author: User

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.

 

  • Problem description

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.

  • Input Format

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.

  • Output Format

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.