solution1(通过50%)
#include<stdio.h>
void f(int a){int t = a;while(a){printf("%d", a % 10);a /= 10;}if(t < 10) printf("0");
}
int isLeap(int n){if(n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) return 1;return 0;
}
int main(){int t, d, m, y, dp, mp, ab[12] = {01011010, 10100101, 11111111, 20200202, 21211212, 30300303, 40400404, 50500505, 60600606, 70700707, 80800808, 90900909};int rd[50] = {1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62, 70, 71, 72, 80, 81, 82, 90, 91, 92};int rm[12] = {1, 10, 11, 20, 21, 30, 40, 50, 70, 80, 90};scanf("%d", &t);d = t / 1000000;m = t / 10000 % 100;for(mp = 0; mp < 12; mp++){if(rm[mp] > m) {m = rm[mp];break;}}y = d * 100 + m;if(m == 20 && isLeap(y) && (d == 3 || d == 13)) m = 21;else if(m == 20 && !isLeap(y) && (d == 92 || d == 3 || d == 31)) m = 21;else if(mp == 12){m = 1;for(int i = 0; i < 50; i++){if(rd[i] > d){d = rd[i];break;}}}printf("%02d%02d", d, m);f(m); f(d);printf("\n");for(int i = 0; i < 50; i++){if(ab[i] > t){printf("%d\n", ab[i]);break;}}return 0;
}
solution2
给出的日期范围是108左右,再加上判断肯定超时,类似之前的思想先用某个限制条件缩小范围。无论是回文串还是满足ABABBABA的数字,共同特点都是需要保证回文,满足该条件的数据量会大大降低。进一步判断该回文数是否满足日期要求
- 1<= 天数<=31
- 1 <=月数<=12
- 闰年的二月<=29天,平年的二月<=28天
- 4,6,9,11月份<=30天
#include<stdio.h>
int isLeap(int y){if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) return 1;return 0;
}
int check(int y, int m, int d){if(d > 31 || d < 1) return 0;if(m > 12 || m < 1) return 0;if(m == 2 && isLeap(y) && d > 29) return 0;if(m == 2 && !isLeap(y) && d > 28) return 0;if(d > 30 && (m == 4 || m == 6 || m == 9 || m == 11)) return 0;return 1;
}
int main(){int t, flag = 1, over = 1;scanf("%d", &t);for(int i = t + 1; i <= 90900909 && over; i++){int a[8] = {0}, temp = i, k, num = 0;do{a[num++] = temp % 10;temp /= 10;}while(temp);for(k = 0; k < 4; k++){if(a[k] != a[7 - k]) break;}if(k == 4){if(check(i / 10000, i / 100 % 100, i % 100)){if(flag){printf("%d\n", i);flag = 0;}if(a[0] == a[2] && a[2] == a[5] && a[5] == a[7] && a[1] == a[3] && a[3] == a[4] && a[4] == a[6]){printf("%d", i);over = 0;}}}}return 0;
}