zwhy


私信TA

用户名:uq_19494209601

访问量:2864

签 名:

等  级
排  名 6449
经  验 1417
参赛次数 0
文章发表 10
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

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 人评分

  评论区

  • «
  • »