hdoj1201簡單題、類比題

來源:互聯網
上載者:User

測試資料:

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;}}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.