|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
int main()
{
int n,day1,day2,month1,month2,year1,year2,year3,year4,temp,y,k;
scanf("%d",&n);
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day;
day=n%100;
//day++;
n=n/100;
month=n%100;
n=n/100;
year=n;
while(1)
{
days[1]=((year%400==0)||(year%4==0&&year%100!=0))?29:28;
while(month<=12)
{
while(day<=days[month-1])
{
temp=year;
day1=day%10;
day2=day/10;
month1=month%10;
month2=month/10;
year1=year%10;
year=year/10;
year2=year%10;
year=year/10;
year3=year%10;
year=year/10;
year4=year;
if((temp*10000+month*100+day)==(day1*10000000)+(day2*1000000)+(month1*100000)+(month2*10000)+(year1*1000)+(year2*100)+(year3*10)+year4)
y=temp*10000+month*100+day;
year=temp;
if((year==(day1*1000)+(day2*100)+(month1*10)+(month2)))
{
k=year*10000+month*100+day;
goto A;
}
}
day=1;
month++;
}
month=1;
year++;
}
A:printf("%d\n",y);
printf("%d\n",k);
return 0;
}
//我不行了。。。。。。。
本帖最后由 jitianmoshen 于 2020-12-11 19:15 编辑
不支持C99的编辑器趁早放弃了, 感觉你每天都有问题啊 #include <stdio.h>
//#include <stdbool.h>
int data_num(int num);
int abcddcba(int num);
int ababbaba(int num);
int runnian(int num);
int main(void)
{
int num,i, f1 = 0, f2 = 0;
printf("请输入一个日期:");
scanf("%d",&num);
for (i = num + 1;i < 100000000;i++)
{
if (abcddcba(i) == 1)
{
if (data_num(i) == 1 && f1 == 0)
{
printf("下一个回文日期是%08d\n",i); //[b]差点忘了年份前面可能有0[/b]
f1 = 1;
}
}
if (ababbaba(i) == 1)
{
if (data_num(i) == 1)
{
printf("下一个ABABBABA型回文日期是%08d\n",i); //[b]差点忘了年份前面可能有0[/b]
f2 = 1;
}
}
if (f1 && f2)
break;
}
return 0;
}
int data_num(int num)
{
int year,month,day;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
year = num / 10000;
month = num % 10000 / 100;
day = num % 100;
days[1]=(runnian(year))?29:28;
if (month > 0 && month <= 12)
{
if (day > 0 && (day <= days[month - 1]))
return 1;
else
return 0;
}
else
return 0;
}
int runnian(int num)
{
if ((num % 400 == 0)||(num % 4 == 0 && num % 100 != 0))
return 1;
else
return 0;
}
int abcddcba(int num)
{
int a1,b1,c1,d1,d2,c2,b2,a2;
a1 = num / 10000000;
b1 = num / 1000000 % 10;
c1 = num / 100000 % 10;
d1 = num / 10000 % 10;
d2 = num / 1000 % 10;
c2 = num / 100 % 10;
b2 = num / 10 % 10;
a2 = num % 10;
if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2)
return 1;
else
return 0;
}
int ababbaba(int num)
{
int a,b,c,d,e,f,g,h;
a = num / 10000000;
b = num / 1000000 % 10;
c = num / 100000 % 10;
d = num / 10000 % 10;
e = num / 1000 % 10;
f = num / 100 % 10;
g = num / 10 % 10;
h = num % 10;
if ((a == c && c == f && f == h) && (b == d && d == e && e == g))
return 1;
else
return 0;
}
|
-
|