试题 历届真题 回文日期【第十一届】【省赛】【B组】提交此题 评测记录
资源限制
时间限制:1.0s 内存限制:256.0MB
哎话说好久没写过日期题了,回忆起刚学的时候被日期统治的恐惧了藍藍
#includeusing namespace std; int months[20]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool chack(int date)//判断日期是否合法 { int year=date/10000; int month=date%10000/100; int day=date%100; if(month<=0||month>12||day==0)return false; if(month!=2&&day>months[month])return false; if(month==2)//二月的日子需要特判一下闰年 { if(year%400==0||(year%4==0&&year%100!=0)) { if(day>29)return false; } else { if(day>28)return false; } } return true; } bool check1(int s) //判断是否是回文日期 { int a=s/10000000; int b=(s/1000000)%10; int c=(s/100000)%10; int d=(s/10000)%10; int e=(s/1000)%10; int f=(s/100)%10; int g=(s/10)%10; int h=s%10; if(a==h&&b==g&&c==f&&d==e) { return true; } return false; } bool check2(int s) //判断是否是回文日期 { int a=s/10000000; int b=(s/1000000)%10; int c=(s/100000)%10; int d=(s/10000)%10; int e=(s/1000)%10; int f=(s/100)%10; int g=(s/10)%10; int h=s%10; if(a==c&&c==f&&f==h&&b==d&&d==e&&e==g&&g!=h) return true; return false; } int main() { int date,flag=0; cin>>date; for(int i=date+1;;i++)//从这天开始之后开始查找 { if(chack(i)) { if(check1(i)&&!flag) { cout<



