思路:把年月日分成三段分别放入三个数组,通过for循环遍历找出符合题目条件日期并输出,至于月份不同通过if else筛选,最后输出通过flag判断是否同时满足题目两个条件
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a[4],b[2],c[2],date,year,month,day,p,flag1=0,flag2=0;
scanf("%d",&date);
year=date/10000;
month=(date%10000)/100;
day=(date%100)+1;
for(;year<9999;year++) {
for(;month<=12;month++) {
if(month==4||month==6||month==9||month==11) p=30;
else if((month==2)&&(((year%4==0)&&(year%100!=0))||(year%400==0))) p=29;
else if(month==2) p=28;
else p=31;
for(;day<=p;day++) {
a[0] = year/1000;
a[1] = (year%1000)/100;
a[2] = (year%100)/10;
a[3] = year%10;
b[0] = month/10;
b[1] = month%10;
c[0] = day/10;
c[1] = day%10;
if(((a[3]==b[0])&&(a[2]==b[1])&&(a[1]==c[0])&&(a[0]==c[1]))&&(flag1==0)) {
printf("%d\n",year*10000+month*100+day);
flag1=1;
}
if(((a[1]==a[3])&&(a[3]==b[0])&&(b[0]==c[0])&&(a[0]==a[2])&&(a[2]==b[1])&&(b[1]==c[1]))&&(flag2==0)) {
printf("%d\n",year*10000+month*100+day);
flag2=1;
}
if((flag1==1)&&(flag2==1)) goto END;
}
day=1;
}
month=1;
}
END: ;
return 0;
}
最后吐槽一下蓝桥杯的oj,直接printf就能通过