Dear Friends:
As much as strings, some numbers are also palindrome. For instance: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ... , 101, 111, ... ,753537, ... and so on.
Here is the thing, We need to figure a way to find first 10.000 palindromic numbers in order to respond user's entry. Starts from 1 to 10000th palindromic number. For example if user enters 12 it means what is the 12th palindromic number between 1 and 10.000 ?
The input consists of a series of lines with each line containing one integer value i (1 <= i <= 10000). This integer value i indicates the index of the palindrome number that is to be written to the output, where index 1 stands for the first palindrome number (1), index 2 stands for the second palindrome number (2) and so on.
EX:
Input 1 --> Output should be: 1
Input 12 --> Output should be: 33
Input 24 --> Output should be: 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);
}
}
- By the way: time limit is 1 second. Considering these factors What is the right Algorithm to solve this problem ? If you could help me and show the solution code wise in Java I would very appreciate it. Thanks for checking!
Maybe not "the very best way", but works fine.
And it does the job in less than 1 sec (depending of your hardware).
I've tested here.