30pts求助

P1167 刷题

Tjaweiof @ 2023-05-05 12:34:06

#include <bits/stdc++.h>
using namespace std;
int n, a[5001], k = 0, ans = 0;
char s1[20], s2[20];
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int yyyy, mm, dd, hh, min1, yyyy2, mm2, dd2, hh2, min2;
bool run(int y){
    if (y % 400 == 0) return 1;
    if (y % 100 == 0) return 0;
    if (y % 4 == 0) return 1;
}
bool cmp(){
    if (yyyy < yyyy2){
        return true;
    } else if (yyyy == yyyy2){
        if (mm < mm2){
            return true;
        } else if (mm == mm2){
            if (dd < dd2){
                return true;
            } else if (dd == dd2){
                if (hh < hh2){
                    return true;
                } else if (hh == hh2){
                    if (min1 <= min2){
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}
void zhuanhuan(int x){
    if (x == 1){
        if (min1 >= 60){
            hh += min1 / 60;
            min1 %= 60;
        }
        if (hh >= 24){
            zhuanhuan(2);
        }
    } else if (x == 2){
        if (hh >= 24){
            dd += hh / 24;
            hh %= 24;
        }
        if (dd >= month[mm]){
            zhuanhuan(3);
        }
    } else if (x == 3){
        if (mm == 2){
            if (run(yyyy)){
                month[2] += 1;
            }
        }
        if (dd >= month[mm]){
            dd += hh / 24;
            hh %= 24;
        }
        month[2] = 28;
        if (mm >= 12){
            zhuanhuan(4);
        }
    } else if (x == 4){
        if (mm >= 12){
            yyyy += mm / 12;
            mm %= 12;
        }
    }
    return;
}
int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    cin >> s1 >> s2;
    yyyy = (s1[0] - 48) * 1000 + (s1[1] - 48) * 100 + (s1[2] - 48) * 10 + (s1[3] - 48);
    mm = (s1[5] - 48) * 10 + (s1[6] - 48);
    dd = (s1[8] - 48) * 10 + (s1[9] - 48);
    hh = (s1[11] - 48) * 10 + (s1[12] - 48);
    min1 = (s1[14] - 48) * 10 + (s1[15] - 48);
    yyyy2 = (s2[0] - 48) * 1000 + (s2[1] - 48) * 100 + (s2[2] - 48) * 10 + (s2[3] - 48);
    mm2 = (s2[5] - 48) * 10 + (s2[6] - 48);
    dd2 = (s2[8] - 48) * 10 + (s2[9] - 48);
    hh2 = (s2[11] - 48) * 10 + (s2[12] - 48);
    min2 = (s2[14] - 48) * 10 + (s2[15] - 48);
    sort(a, a + n);
    while (cmp()){
        min1 += a[k++];
        zhuanhuan(1);
        ans++;
    }
    cout << ans - 1;
    return 0;
}

感谢各位大佬


|