文章

18

粉丝

1

获赞

17

访问

522

头像
日期计算 题解:
P1051 中南大学机试题
发布于2026年3月16日 00:21
阅读数 30

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm> 
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int year, month, day, sum;
    int days1[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    int days2[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
    while (cin >> year >> month >> day) {
        if (year < 1) {
            cout << "Input error!" << endl;
            continue;
        }
        if (month < 1 || month > 12){
            cout << "Input error!" << endl;
            continue;
        }
        if (day < 1 || day > 31){
            cout << "Input error!" << endl;
            continue;
        }
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            sum = 0;
            for (int i = 0; i < month - 1; i++) {
                sum = sum + days2[i];
           ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发