题目描述
输入年、月、日,计算该天是本年的第几天。
输入描述:
包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
输出描述:
输入可能有多组测试数据,对于每一组测试数据, 输出一个整数,代表Input中的年、月、日对应本年的第几天。
示例1
输入
1990 9 20 2000 5 1
输出
263 122
思路:就是对年份的判断,判断是否为闰年;其次要知道闰年2月是29天!!!第一次未通过,把闰年2月份当成28天了,基本常识也是醉了。。。。。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int y,m,d;
while(cin>>y>>m>>d)
{
int run_month[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年2月是29天
int sum=0;
if(y%400==0||(y%4==0&&y%100!=0))
{
for(int i=1;i<m;i++)
{
sum+=run_month[i];
}
sum+=d;
}
else{
run_month[2]=28;//平年的更新2月的天数为28天
for(int i=1;i<m;i++)
{
sum+=run_month[i];
}
sum+=d;
}
cout<<sum<<endl;
}
return 0;
}