解题思路通过外层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语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:932 |
【亲和数】 (C语言代码)浏览:530 |
拆分位数 (C语言代码)浏览:1361 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:900 |
三角形 (C++代码)递推浏览:825 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:751 |
数字游戏 (C++代码)浏览:1240 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:465 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:653 |