为什么我错了,哪位大佬帮忙看看?

lyh198 波风水门 2024-08-18 19:02:10 5

#include <bits/stdc++.h>

using namespace std;

int main() { int a, b, c, d, e, t;

int s = 0;

cin >> a >> b >> c;

cin >> d >> e >> t;

int k = d - a;

for (int i = a; i <= d - 1; i++) {
    if (i % 400 == 0 || i % 4 == 0 && i % 100 != 0) {
        s = s + 29;

    } else {
        s = s + 28;
    }
}

s = s + k * 4 * 30 + k * 7 * 31;

int y = 0;

for (int i = 1; i <= b - 1; i++) {
    if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
        y = y + 31;

    } else if (i == 2) {
        if (a % 400 == 0 || a % 4 == 0 && a % 100 != 0) {
            y = y + 29;

        } else {
            y = y + 28;
        }

    } else {
        y = y + 30;
    }
}

y = y + d;

int w = 0;

for (int i = 1; i <= e - 1; i++) {
    if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
        w = w + 31;

    } else if (i == 2) {
        if (d % 400 == 0 || d % 4 == 0 && d % 100 != 0) {
            w = w + 29;

        } else {
            w = w + 28;
        }

    } else {
        w = w + 30;
    }
}

w = w + t;

s = s + w - y;

cout << s;

}

{{ vote && vote.total.up }}

共 1 条回复

root 站长

46 行的变量写错了

   y = y + d;

应该是加天数c