Palindrome number
(0371)
Problem description
A natural number if all the numbers upside down and the same as the original, then we call it a palindrome number. For example 151 and 753357. We can arrange all the palindrome numbers from small to large rows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ... Note that 10 is not a palindrome number, although we can write it in 010, but the leading 0 in the subject is not allowed.
your task is to find the small palindrome number of the first I. For example, the number of palindrome 1,12,24 large is 1, 33,151 respectively.
enter
Enter only one line, that is, I (1<=i<=2*10^9).
output
The output is only one row, that is, the small palindrome number of I.
example input
24
example output
151
Constructing palindrome number and water problem
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;#definell Long Long#defineN 100010ll N;ll a[]={0,9,9, -, -, the, the,9000,9000,90000,90000,900000,900000,9000000,9000000,90000000,90000000,900000000,900000000,9000000000};ll b[ -],len;intMain () {ll k,t,i,bk; while(SCANF ("%lld", &n)! =EOF) {Len=0; K=1; while(n-a[k]>0) n-=a[k++]; BK= (k +1) >>1; T=1; for(i=2; i<=bk;i++) t*=Ten; T+=n-1; while(t) {b[++len]=t%Ten; T/=Ten; } for(i=len;i>=1; i--) cout<<B[i]; for(i=k&1?2:1; i<=len;i++) cout<<B[i]; cout<<Endl; } return 0;}
[Swustoj 371] palindrome number