蒟蒻求助orz

P2010 [NOIP2016 普及组] 回文日期

TomLovesRita @ 2018-10-23 19:38:06

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct date {
    int n;
    int year;
    int month;
    int day;
}date1, date2;
bool pdyear(date);
bool pdmonth(date);
bool pddate(date);
int pdnum(date);
inline int read(void);
bool pd(date);
void set(date);
bool pdhw(date);
void solve(void);
int main() {
    date1.n=read();
    date2.n=read();
    set(date1);
    set(date2);
    solve();
    return 0;
}
inline int read(void) {
    int flag=1, x=0;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-') flag=-flag;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*flag;
}
bool pdyear(date a) {
    if(a.year%100==0) {
        if(a.year%400==0) return 1;
        else return 0;
    }
    else {
        if(a.year%4==0&&a.year%100!=0) return 1;
        else return 0;
    }
}
bool pdmonth(date a) {
    if(a.month>12||a.month<1) return 0;
    else return 1;
}
int pdnum(date a) {
    if(a.month==1||a.month==3||a.month==5||a.month==7||a.month==8||a.month==10||a.month==12) return 31;
    else if(a.month==4||a.month==6||a.month==9||a.month==11) return 30;
    else if(a.month==2) {
        if(pdyear(a)) return 29;
        else return 28;
    }
}
bool pdday(date a) {
    if(a.day>pdnum(a)) return 0;
    if(a.day==0) return 0;
    return 1;
}
bool pd(date a) {
    if(pdyear(a)&&pdmonth(a)&&pdday(a)) return 1;
    else return 0;
}
void set(date &a) {
    a.year=a.n/10000;
    a.month=(a.n/100)%100;
    a.day=a.n%100;
}
bool pdhw(date a) {
    int p[9];
    p[1]=a.n/10000000;
    p[2]=(a.n/1000000)%10;
    p[3]=(a.n/100000)%10;
    p[4]=(a.n/10000)%10;
    p[5]=(a.n/1000)%10;
    p[6]=(a.n/100)%10;
    p[7]=(a.n/10)%10;
    p[8]=a.n%10;
    if(p[1]==p[8]&&p[2]==p[7]&&p[3]==p[6]&&p[4]==p[5]) return 1;
    else return 0;
}
void solve(void) {
    int counter=0;
    date i;
    for(i.n = date1.n; i.n <= date2.n; i.n++) {
        if(pd(i)&&pdhw(i)) counter++;
    }
    printf("%d\n", counter);
    return ;
}

请问哪里出了问题orz


by TomLovesRita @ 2018-10-24 18:06:30

MZ


by yxf123456 @ 2018-10-27 11:36:57

include<cstdio>

include<iostream>

using namespace std;

char op[9]; char ed[9];

int y(char s[]) { int year = 0; for(int i = 0; i < 4; i++) { year *= 10; year += s[i] - '0'; } return year; }

int m(char s[]) { int month = s[4] - '0'; return month * 10 + s[5] - '0'; }

int d(char s[]) { int day = s[6] - '0'; return day * 10 + s[7] - '0'; }

int m(int y) { int b = y % 10; int a = (y / 10) % 10; return b * 10 + a; }

int d(int y) { y /= 100; return m(y); }

int mday[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool abnorm(int year) { if(year % 4 == 0 && year % 100 != 0) return true; if(year % 400 == 0) return true; return false; }

int main() { scanf("%s%s", op, ed); int opy = y(op), opm = m(op), opd = d(op); int edy = y(ed), edm = m(ed), edd = d(ed); int ans = 0; for(int year = opy; year <= edy; year++) { int month = m(year), day = d(year); if(month < 1 || month > 12) continue; if(day < 1 || day > mday[month]) continue; if(!abnorm(year) && month == 2 && day == 29) continue; if(year == opy) { if(month < opm || (month == opm && day < opd)) continue; } if(year == edy) { if(month > edm || (month == edm && day > edd)) continue; } ans++; } cout << ans << endl; return 0; }


by yxf123456 @ 2018-10-27 11:38:00

借贵地发下共享题解


by yxf123456 @ 2018-10-27 11:38:23

题解审核时间太长


by yxf123456 @ 2018-10-27 11:39:24

include<cstdio>

include<iostream>

using namespace std;

char op[9]; char ed[9];

int y(char s[]) { int year = 0; for(int i = 0; i < 4; i++) { year *= 10; year += s[i] - '0'; } return year; }

int m(char s[]) { int month = s[4] - '0'; return month * 10 + s[5] - '0'; }

int d(char s[]) { int day = s[6] - '0'; return day * 10 + s[7] - '0'; }

int m(int y) { int b = y % 10; int a = (y / 10) % 10; return b * 10 + a; }

int d(int y) { y /= 100; return m(y); }

int mday[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool abnorm(int year) { if(year % 4 == 0 && year % 100 != 0) return true; if(year % 400 == 0) return true; return false; }

int main() { scanf("%s%s", op, ed); int opy = y(op), opm = m(op), opd = d(op); int edy = y(ed), edm = m(ed), edd = d(ed); int ans = 0; for(int year = opy; year <= edy; year++) { int month = m(year), day = d(year); if(month < 1 || month > 12) continue; if(day < 1 || day > mday[month]) continue; if(!abnorm(year) && month == 2 && day == 29) continue; if(year == opy) { if(month < opm || (month == opm && day < opd)) continue; } if(year == edy) { if(month > edm || (month == edm && day > edd)) continue; } ans++; } cout << ans << endl; return 0; }


by yxf123456 @ 2018-10-27 11:39:47

不好意思


|