解题思路通过外层for循环年份,内层while循环月份遍历所有日期
注意事项:暴力求解并不能拿到所有分数,但可以拿到绝大多数分
参考代码:
#include<stdio.h>
int judge(int n) {
int a = n / 10000000;//第一位
int b = n / 1000000 % 10;//第二位
int c = n / 100000 % 10;//第三位
int d = n / 10000 % 10;//第四位
int e = n / 1000 % 10;//第五位
int f = n / 100 % 10;//第六位;
int g = n / 10 % 10;//第七位;
int h = n % 10;//第八位
int t = 0;
if (a == c && a == f && a == h && b == d && b == e) t = 1;
if (a == h && b == g && c == f && d == e && t == 0) {
return 1;//回文
}
if (a == c && a == f && a == h && b == d && b == e && b == g) {
return 2;//ababbaba
}
return 0;
}
int main() {
int n;
scanf("%d", &n);
int year = n / 10000;
int still = year;
int month = n / 100 % 100;
int day = n % 100 + 1;
int j = 0, k[1000], l[1000], i = 0, m = 0;
int d;
for (year; year < still + 10000; year++) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
d = 1; //闰年
else d = 2; //非润年
int yy = year % 10, ym = year % 100 / 10;
while (month <= 12) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
for (day; day <= 31; day++) {
int t = year * 10000 + month * 100 + day;
j = judge(t);
if (j == 1) {
k[i] = t; //回文
i++;
} else if (j == 2) {
l[m] = t; //abab型
m++;
}
}
if (j == 0) {
day = 1;
month++;
}
}
if (month == 4 || month == 6 || month == 9 || month == 11) {
for (day; day <= 30; day++) {
int t = year * 10000 + month * 100 + day;
j = judge(t);
if (j == 1) {
k[i] = t; //回文
i++;
} else if (j == 2) {
l[m] = t; //abab型
m++;
}
}
if (j == 0) {
day = 1;
month++;
}
}
if (month == 2 && d == 1) {
for (day; day <= 29; day++) {
int t = year * 10000 + month * 100 + day;
j = judge(t);
if (j == 1) {
k[i] = t; //回文
i++;
} else if (j == 2) {
l[m] = t; //abab型
m++;
}
}
if (j == 0) {
day = 1;
month++;
}
}
if (month == 2 && d == 2) {
for (day; day <= 28; day++) {
int t = year * 10000 + month * 100 + day;
j = judge(t);
if (j == 1) {
k[i] = t; //回文
i++;
} else if (j == 2) {
l[m] = t; //abab型
m++;
}
}
if (j == 0) {
day = 1;
month++;
}
}
}
month = 1;
if (i > 0 && m > 0) break;
}
printf("%d\n", k[0]);
printf("%d", l[0]);
}
0.0分
4 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复