亲爱的朋友们:
与字符串一样,一些数字也是回文。例如:1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ... , 101, 111, ... ,753537, ... 等等。
事情是这样的,我们需要想办法找到前 10.000 个回文数字,以便响应用户的输入。从第 1 到第 10000 个回文数开始。 例如,如果用户输入 12,则表示 1 到 10.000 之间的第 12 个回文数是多少?
输入由一系列行组成,每行包含一个整数值 i (1 <= i <= 10000)。这个整数值 i 表示要写入输出的回文数的索引,其中索引 1 代表第一个回文数 (1),索引 2 代表第二个回文数 (2),依此类推。
前任:
输入 1 --> 输出应该是:1
输入 12 --> 输出应该是:33
输入 24 --> 输出应该是:151
import java.util.Scanner;
public class xth_palindrome
{
// Some Code may be here
public static void main(String[] args)
{
@SuppressWarnings("resource")
Scanner read = new Scanner(System.in);
System.out.println("Enter values as much as you want. To stop Enter \"0\" ");
int Xth;
do
{
Xth = read.nextInt();
// Some coding here
System.out.println(Xth + " palindromic num is " + "????");
} while(Xth != 0);
}
}
- 顺便说一句:时间限制是1秒。 考虑到这些因素解决这个问题的正确算法是什么?如果您能帮助我并在 Java 中明智地展示解决方案代码,我将不胜感激。感谢您的检查!