70分求助

P2010 [NOIP2016 普及组] 回文日期

kent3 @ 2022-10-10 22:30:33

#include <iostream>
using namespace std;
string s1, s2;
int q1, q2, q3, z1, z2, z3, res;
bool pd(int x, int y, int z) {
    if (x / 1000 == z % 10 && x % 1000 / 100 == z / 10 && x % 100 / 10 == y % 10 && x % 10 == y / 10) return 1;
    return 0;
}
bool isr(int n) {
    if (n % 4 == 0 && n % 100 != 0) return 1;
    if (n % 100 == 0 && n % 400 == 0) return 1;
    return 0;
}
int main() {
    cin >> s1 >> s2;
    q1 = (s1[0]-'0') * 1000 + (s1[1] - '0') * 100 + (s1[2] - '0') * 10 + (s1[3] - '0');
    q2 = (s1[4] - '0') * 10 + (s1[5] - '0');
    q3 = (s1[6] - '0') * 10 + (s1[7] - '0');
    z1 = (s2[0] - '0') * 1000 + (s2[1] - '0') * 100 + (s2[2] - '0') * 10 + (s2[3] - '0');
    z2 = (s2[4] - '0') * 10 + (s2[5] - '0');
    z3 = (s2[6] - '0') * 10 + (s2[7] - '0');
    for (int i = q1; i <= z1; i++) {
        if (i == q1) {
            for (int j = q2; j <= 12; j++) {
                if (isr(i)&&j==2) {
                    for (int k = q3; k <= 29; k++){
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if(j==2){
                    for (int k = q3; k <= 28; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
                    for (int k = q3; k <= 30; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else {
                    for (int k = q3; k <= 31; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
            }
        }
        else if (i == z1) {
            for (int j = 1; j <= z2; j++) {
                if (isr(i) && j == 2) {
                    for (int k = q3; k <= 29; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if (j == 2) {
                    for (int k = q3; k <= 28; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12) {
                    for (int k = q3; k <= 30; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else {
                    for (int k = q3; k <= 31; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
            }
        }
        else {
            for (int j = 1; j <= 12; j++) {
                if (isr(i) && j == 2) {
                    for (int k = q3; k <= 29; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if (j == 2) {
                    for (int k = q3; k <= 28; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12) {
                    for (int k = q3; k <= 30; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
                else {
                    for (int k = q3; k <= 31; k++) {
                        if (pd(i, j, k)) {
                            res++;
                        }
                    }
                }
            }
        }
    }
    cout << res;// << z1 << z2 << z3 << q1 << q2 << q3;
    return 0;
}

by Curry_Skyfxxker @ 2022-10-10 22:36:58

@kent3 推荐不要一起堆在主函数,多开几个,就能找到问题


by kent3 @ 2022-10-14 21:26:47

OK


|