2017.10.25

日期计算

时间限制: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






#include <iostream>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
int N;
int year,month,day;
int sum=0;
int Month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
scanf("%d",&N);
for(int k=0;k<N;k++)
{
scanf("%d",&year);
scanf("%d",&month);
scanf("%d",&day);
if((year%4==0)&&(year%100!=0)||(year%400==0))    //闰年 能被4整除且不能被100整除或者能被400整除
{
Month[1]=29;
}
else
{
Month[1]=28;
}
for(int i=0;i<month-1;i++)
{
sum+=Month[i];
}
sum+=day;
printf("%d ",sum);
sum=0;
}
return 0;
}



原文地址:https://www.cnblogs.com/panlangen/p/7730010.html