随意输入一个年月日,计算那天是那年的第几天。
输入格式
输入三个整数,分别代表 年 月 日,用空格隔开。
输出格式
输出一个整数,表示输入的日期是当年第几天。
样例输入
2022 10 15
样例输出
288
样例输入
2022 6 8
样例输出
159
代码:
#include<iostream>
using namespace std;
int daynum(int year,int moth){
int day;
if(moth==1||moth==3||moth==5||moth==7||moth==8||moth==10||moth==12){
day=31;
}else if(moth==2){
if(year%4==0&&year%100!=0||year%400==0){ //闰年
day=29;
}else{
day=28;
}
}else{ //4,6,9,11月
day=30;
}
return day;
}
int main(){
int year,moth,day;
while(cin>>year>>moth>>day){
int sum=0;
for(int i=1;i<moth;i++){
sum+=daynum(year,i);
}
sum+=day;
cout<<sum<<endl;
}
return 0;
}