今年的第几天
描述
输入年、月、日,计算该天是本年的第几天。
输入描述:
包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
输出描述:
输入可能有多组测试数据,对于每一组测试数据, 输出一个整数,代表Input中的年、月、日对应本年的第几天。
要点 闰年 每月天数
#include <bits/stdc++.h>
using namespace std;
int main(){
int year,month,day;
int DayofMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while(scanf("%d%d%d",&year,&month,&day)!=EOF){
int totalday=1;
if(year%400==0||(year%4==0&&year%100!=0)){
DayofMonth[2]=29;
}else{
DayofMonth[2]=28;
}
for(int i=1;i<month;++i){
totalday+=DayofMonth[i];
}
for(int j=1;j<day;++j){
totalday++;
}
printf("%d\n",totalday);
}
}