NYOJ 75

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34075012/article/details/78528798

日期计算

时间限制: 3000 ms  |  内存限制: 65535 KB
难度: 1
描述
如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
输入
第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。
输出
每组输入数据的输出占一行,输出判断出的天数n
样例输入
3
2000 4 5
2001 5 4
2010 10 24
样例输出
96
124
297

AC代码:

 
#include <iostream>
#include <cstdio>

using namespace std;

int day[12] ={0,31,59,90,120,151,181,212,243,273,304,334};

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int year,month,date,sum = 0;
        scanf("%d%d%d",&year,&month,&date);
        sum = day[month-1] + date;
        if(year % 100 ==0){
            if(year % 4 == 0&&month > 2){
                sum = sum+1;
            }
        }
        else{
            if(year % 4 == 0&&month > 2){
                sum = sum+1;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
        


猜你喜欢

转载自blog.csdn.net/qq_34075012/article/details/78528798
75