萌新求救c⌒っ゚Д゚)っ

P2010 [NOIP2016 普及组] 回文日期

AC的荣耀 @ 2018-10-22 22:47:03

样例都过不了QAQ

#include<bits/stdc++.h>
using namespace std;
int n,m,day1,day2,mon1,mon2,yea1,yea2,ans=0;
int hw(string s)
{
    int x,y;
    x=0;
    y=7;
    while(s[x]==s[y])
    {
        if(s[x]!=s[y]) return 0;
        if(y-x==1) return 1; 
        x++;
        y--;
    }
}
int check(int o)
{
    if((!o%4 && o%100) || !o%400) return 0;
    else return 1;
}
int main()
{
    cin>>n>>m;
    day1=n%100;
    day2=m%100;
    mon1=n/100%100;
    mon2=m/100%100;
    yea1=n/10000;
    yea2=m/10000;
    while(day1!=day2 || mon1!=mon2 || yea1!=yea2)
    {
        if(day1==32 && (mon1==1 || mon1==3 || mon1==5 || mon1==7 || mon1==8 || mon1==10 || mon1==12))
        {
            day1=1;
            mon1++;
        }
        if(day1==31 && (mon1==4 || mon1==6 || mon1==9 || mon1==11))
        {
            day1=1;
            mon1++;
        }
        if(day1==29 && mon1==2 && check(yea1))
        {
            day1=1;
            mon1++;
        }
        if(day1==30 && mon1==2 && !check(yea1))
        {
            day1=1;
            mon1++;
        }
        if(mon1==13)
        {
            yea1++;
            mon1=1;
            day1=1;
        }
        string da,mo,ye,res;
        stringstream ss;
        ss<<day1;
        ss>>da;
        if(da.size()<2) da="0"+da; 
        ss<<mon1;
        ss>>mo;
        if(mo.size()<2) mo="0"+mo;
        ss<<yea1;
        ss>>ye;
        res=ye+mo+da;
        if(hw(res)) ans++;
        day1++;
    }
    cout<<ans;
}

by resftlmuttmotw @ 2018-10-22 23:12:50

哪题


by AC的荣耀 @ 2018-10-22 23:49:14

@resftlmuttmotw 回文日期


|