Codeup cemetery - Problem E: Date accumulate

Title Description

Design a program can calculate a date plus the number of days what date.

Entry

Input of the first line indicates the number of samples m, m next four lines each represent an integer of date and the number of days accumulated.

Export

M output lines, each output according to the number of yyyy-mm-dd.

Sample input

1
2008 2 3 100

Sample Output

2008-05-13
#include <stdio.h>
int month[13][2]= {{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}};
int isLeapyear(int year)   //判断是否是闰年
{
    if((year%4==0&&year%100!=0)||(year%400==0))
        return 1;
    else
        return 0;
}
int main()
{
    //month存储天数,一维代表平年,二维代表闰年
    int n,y,m,d,t;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d %d %d %d",&y,&m,&d,&t);   //输入数据
        while(t--)
        {
            d++;      //日期加1
            if(d==month[m][isLeapyear(y)]+1)  //判断是否满月
            {
                m++;
                d=1;
            }
            if(m==13)     //判断是否满年
            {
                y++;
                m=1;
            }
        }
        printf("%d-%02d-%02d\n",y,m,d);
    }
    return 0;
}

operation result:

Published 462 original articles · won praise 55 · views 320 000 +

Guess you like

Origin blog.csdn.net/LY_624/article/details/88781299