思路
这道题无非就是区分不同月份天数不一样,以及闰年、平年的区别而已。
#include<iostream> using namespace std; int main(){ int year, month, day; int days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31} }; while(cin >> year >> month >> day){ int sum = 0; //判断是否是闰年 if((year%100 != 0 && year%4 == 0)|| year%400 == 0){ for(int i = 1; i < month; i ++) sum += days[1][i]; }else{ for(int i = 1; i < month; i ++) sum += days[0][i]; } cout << sum + day << endl; } return 0; }