解题思路:

注意事项:

参考代码:

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.0分

2 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论