今年的第几天? 点击打开链接
题目描述
输入年、月、日,计算该天是本年的第几天。
输入描述:
包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
输出描述:
输入可能有多组测试数据,对于每一组测试数据, 输出一个整数,代表Input中的年、月、日对应本年的第几天。
示例1
输入
1990 9 20 2000 5 1
输出
263 122
AC代码:
#include <iostream>
using namespace std;
bool IsLeapYear(int n){
if(((n%4==0)&&(n%100!=0))||(n%400==0)){
return true;
}
else{
return false;
}
}
int main(int argc, char** argv) {
int monthDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day;//当前年月日
int days;//总日子数
while(cin>>year>>month>>day){
if(IsLeapYear(year)){
monthDay[1]=29;
}
else{
monthDay[1]=28;
}
days=0;
for(int i=0;i<month-1;i++){
days+=monthDay[i];
}
days+=day;
cout<<days<<endl;
}
return 0;
}