測試資料:
10
1980-02-29
-1
1988-03-03
6574
1987-03-03
6575
1970-03-03
6575
1988-02-02
6575
1987-02-02
6575
1970-02-02
6574
1988-02-28
6575
1970-02-28
6574
1987-02-28
6575
Press any key to continue . . .
#include<iostream>//注意找規律,不要一天一天的類比#include<string>using namespace std;bool is_leap(int year){if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){return true;}else{return false;}}int main(){int m;cin>>m;string s;int year;int month;int day;int count;for(int i = 0; i < m; i++){cin>>s;year = (s[0] - 48) * 1000 + (s[1] - 48) * 100 + (s[2] - 48) * 10 + (s[3] - 48);month = (s[5] - 48) * 10 + (s[6] - 48);day = (s[8] - 48) * 10 + (s[9] - 48);if(is_leap(year) && month == 2 && day == 29){cout<<-1<<endl;continue;}count = 0;if(month <= 2){if(is_leap(year)){count++;}}year++;for(int j = 1; j <= 18; year++, j++){if(is_leap(year)){count++;}}year--;if(is_leap(year) && month <= 2){count--;}cout<<6570 + count<<endl;}}