杭电ACM2005:第几天

来源:互联网 发布:软件质量管理体系分类 编辑:程序博客网 时间:2024/06/05 04:15
#include <iostream>using namespace std;int main(){    int year, month, day,s;    char c;    while (cin >> year >> c >> month >> c >> day){        switch (month){        case 1:s = 0; break;        case 2:s = 31; break;        case 3:s = 59; break;        case 4:s = 90; break;        case 5:s = 120; break;        case 6:s = 151; break;        case 7:s = 181; break;        case 8:s = 212; break;        case 9:s = 243; break;        case 10:s = 273; break;        case 11:s = 304; break;        case 12:s = 334; break;        default:cout << "error" << endl; break;        }        if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)){            if (month > 2) s += 1;        }        cout << s + day << endl;    }    return 0;}

年月日输入、读取
闰年
2月
月份对应天数

0 0
原创粉丝点击