Ccf201509-2 Date Calculation (100 points) __ Date Calculation

Source: Internet
Author: User


Question number: 201509-2
Question Name: Date Calculation
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: Problem description Given a year y and an integer d, ask what day D of the year is a few months.
Note that the leap year of February has 29 days. A leap year satisfies one of the following conditions:
1 The year is an integer multiple of 4, and is not 100 integral times;
2) The year is an integer multiple of 400. The first line entered in the input format contains an integer y that represents the year, between 1900 and 2015 (including 1900 and 2015).
The second line entered contains an integer d,d between 1 and 365. The output format outputs two rows, one integer per line, and the month and date of the answer, respectively. Sample input 2015
80 Sample Output 3
21 Sample Input 2000
40 Sample Output 2
9

Question Link: CCF201509 questions.

Problem Description :

Given a year y and an integer d, ask what day D of the year is a few months.

Problem Analysis :

You need to be aware of leap year issues. According to the number of days D, monthly calculation month, and finally calculate the month of days, that is, the number of days by month minus January days, February days 、... Method of calculation.

Program Description :

Use array days[] to store the number of days per month. Use the Isleapyear () to adjust the number of days of February by using the function of year to determine leap years.


The C + + language program after submitting 100 points is as follows:

/* ccf201509-2 Date Calculation *

/#include <iostream>

using namespace std;

int days[12] = [to], from, to, from, to, from, to;

Leap year COMPUTE function
int leapyear (int year) {return (
    year%4 = = 0 && year%100!= 0) | | year%400 = 0)? 1:0;

int main ()
{
    int y, D, month=0, day, I;

    Input data
    cin >> y >> D;

    Calculate month and day
    days[1] + + = leapyear (y);
    i = 0;
    while (d > 0) {
        if (d <= days[i]) {
            month = i + 1;
            Day = D;
            break;
        else {
            D-= days[i];
            i++
        }
    }

    Output results
    cout << month << Endl << day << Endl;

    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.