A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,
The name "Anna" is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally
Numbers can of course is ordered in size. The. RST few palindrome numbers are:1, 2, 3, 4, 5, 6, 7, 8,
9, 11, 22, 33, ...
The number is not a palindrome (even though you could write it as 010) but a zero as leading
Digit is not allowed.
Input
The input consists of a series of lines with each line containing one integer value I (1≤i≤2∗109
).
This integer value I indicates the index of the palindrome number, which is to was written to the output,
Where Index 1 stands for the. RST palindrome number (1), index 2 stands for the second palindrome
Number (2) and so on. The input is terminated by a line containing ' 0 '.
Output
For each line of input (except the last one) exactly one line of output containing a single (decimal)
The integer value is-to-be produced. For each input value i the i-th palindrome number are to be written to
The output.
Sample Input
1
12
24
0
Sample Output
1
33
151
Test Instructions : Given i, output I palindrome number, cannot have a leading 0.
The first and last one is not 0,
We preprocess the number of I digits and how many cases I have in the case of not the first and last
Just keep dividing it.
//Meek///#include <bits/stdc++.h>#include <cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>#include<bitset>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>using namespacestd;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_back#defineFi first#defineSe Second#defineMP Make_pairtypedefLong Longll;Const intN =1050;Const intM =1000001;Const intINF =0x3f3f3f3f;Const intMOD =1000000007;Const DoubleEPS =0.000001; ll A[n],sum[n],b[n],s;voidInit () {s=0; a[1] =Ten; b[1] =9; a[2] =Ten; b[2] =9; for(intI=3; i<= -; i++) {A[i]= a[i-2] *Ten; }s= -; for(intI=3; i<= -; i++) {B[i]=9*a[i-2]; S+=B[i]; //cout<<s<<endl; }}intMain () {init (); ll N, num, ans[n]; while(SCANF ("%lld", &n)! =EOF) { if(!n) Break; Mem (ans); intl,r,mm; for(intI=1; i<= -; i++) { if(b[i]>=n) {num=i; MM=num; L=1, r =num; while(l<=r) {if(num = =1) { if(l!=1) n--; ANS[L]=N; ANS[R]= N; Break; } if(num = =2) { if(l!=1) n--; ANS[L]=N; ANS[R]= N; Break; } Ans[l]= n/a[num-2] + (L = =1?1:0); N= n%a[num-2]; if(n = =0&& num-2!=0) {Ans[l]--; N= a[num-2]; } Ans[r]=Ans[l]; L++,r--;num-=2; } Break; } N-=B[i]; } for(intI=1; i<=mm;i++) printf ("%lld", Ans[i]); printf ("\ n"); } return 0;}
Code
Poj2402/uva 12050 palindrome Numbers Mathematical Thinking