import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
int n=0;
for(int i=2022;i<=2022222022;i++){
if(huiwen(i)){
if(dizeng(i)){
n++;
}
}
}
System.out.println(n);
scan.close();
}
public static boolean huiwen(int i){
String s = String.valueOf(i);
int left = 0;
int right = s.length() - 1;
while (left < right){
if (s.charAt(left) == s.charAt(right)){
left++;
right--;
}else {
return false;
}
}
return true;
}
public static boolean dizeng(int i){
String s = String.valueOf(i);
int start = 0;
while (start < s.length()/2){
if (s.charAt(start) < s.charAt(start+1)){
start++;
}else {
return false;
}
}
return true;
}
}
解题思路:
1.以前写过关于“回文数”的题目,但是一直都是暴力法,且不会考虑递增,现在要两重判断,网站运行不给通过;
2.看到人家用数学分析了回文数的逻辑后,感觉题目应该是想我们这样解