题目描述

这天小明正在学数数。
他突然发现有些正整数的形状像一座“山”,比如123565321、145541。
它们左右对称(回文)且数位上的数字先单调不减,后单调不增。
小明数了很久也没有数完,他想让你告诉他在区间[2022:2022222022]中有多少个数的形状像一座“山”。
这是一道结果填空的题,你只需要算出结果后提交即可。
本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

代码详解

public class Main {
public static void main(String[] args) {
int count = 0;
int top = 0;
f:
for (long i = 2022; i <= 2022222022; i++) {
String str = String.valueOf(i);
for (int j = 0; j < str.length(); j++) {

if (str.charAt(j) != str.charAt(str.length() - j - 1)) {
continue f;
}

if (j<str.length()/2){
if ((str.charAt(j)-'0')>(str.charAt(j+1)-'0')){
continue f;
}
}

}
count++;
System.out.println(i);
}
System.out.println(count);
}
}

点击并拖拽以移动