题目描述输入年、月、日,计算该天是本年的第几天。输入描述:包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。输出描述:输入可能有多组测试数据,对于每一组测试数据,输出一个整数,代表Input中的年、月、日对应本年的第几天。示例1输入1990 9 202000 5 1输出263122
#include<stdio.h>
#include<string.h>
int Run[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int Ping[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int isRun(int year){
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return 1;
}else{
return 0;
}
}
int cal(int year, int month, int day){
int result = 0;
if(isRun(year)){
for(int i = 0; i < month-1; i++){
result = result + Run[i];
}
result = result + day;
}else{
for(int i = 0; i < month-1; i++){
result = result + Ping[i];
}
result = result + day;
}
return result;
}
int main(){
int year, month, day;
while(scanf("%d%d%d", &year, &month, &day)) {
printf("%d\n", cal(year, month, day));
}
return 0;
}