解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
static int[] Month = {31,28,31,30,31,30,31,31,30,31,30,31};
public static void main(String[] args) {
//
//处理一下可能的回文串即可
String[] before2 = {"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"};
String[] after2 = {"01","10","11","20","21","30","40","50","60","70","80","90"};
Scanner sc = new Scanner(System.in);
String str = sc.next();
int n = Integer.parseInt(str);
int flag1= 0;
int flag2 = 0;
int recNum = -1;
int abNum = -1;
for (int i = 0; i < before2.length; i++) {
for (int j = 0; j < after2.length; j++) {
if (flag1 == 1 && flag2 == 1) {
break;
}
String[] arr = new String[2];
StringBuilder sb2 = new StringBuilder();
sb2.append(before2[i]).append(after2[j]).reverse();
StringBuilder sb1 = new StringBuilder();
sb1.append(before2[i]).append(after2[j]);
StringBuilder sb3 = new StringBuilder(sb1.toString() + sb2.toString());
arr[0] = before2[i];
arr[1] = after2[j];
int res = Integer.parseInt(sb3.toString());
if (res > n && res <= 92909290 && valid(arr)) {
if (flag1 == 0) {
recNum = res;
flag1 = 1;
}
if (flag2 == 0 && arr[0].compareTo(arr[1]) == 0) {
abNum = res;
flag2 = 1;
}
}
}
}
System.out.println(recNum);
System.out.println(abNum);
}
public static boolean valid(String[] arr) {
int tmp = Integer.parseInt(arr[0]) / 10;
int day = Integer.parseInt(arr[0]) % 10 * 10 + tmp;
int tmp2 = Integer.parseInt(arr[1]) / 10;
int month = Integer.parseInt(arr[1]) % 10 * 10 + tmp2 - 1;
if (isLeapYear(arr[0] + arr[1])) {
Month[1] = 29;
}
if (day <= Month[month]) {
Month[1] = 28;//不进入判断都是平年
return true;
}
Month[1] = 28;
return false;
}
public static boolean isLeapYear(String y) {
int year = Integer.parseInt(y);
if(year % 400 == 0 || year % 100 != 0 && year % 4== 0) {
return true;
}
return false;
}
}
0.0分
2 人评分
【亲和数】 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:591 |
简单的a+b (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:710 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:645 |
1128题解(返回值为数组的情况)浏览:571 |
DNA (C语言代码)浏览:837 |
矩形面积交 (C语言代码)浏览:1433 |
C二级辅导-统计字符 (C语言代码)浏览:695 |
整除的尾数 (C语言代码)浏览:852 |