[Swustoj 371] palindrome number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.