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 be ordered in size. The first few palindrome numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ...

The number 10 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 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. 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) integer value is to be produced. For each input value i the i-th palindrome number is to be written to the output.

Sample Input

1

12

24

0

Sample Output

1

33

151

题意:求第n个回文串
思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是,
n计算完后要-1
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = ;
ll num[maxn];
int n, ans[maxn];
void init() {
num[] = , num[] = num[] = ;
for (int i = ; i < ; i += )
num[i] = num[i+] = num[i-] * ;
}
int main() {
init();
while (scanf("%d", &n) && n) {
int len = ;
while (n > num[len]) {
n -= num[len];
len++;
}
n--;
int cnt = len / + ;
while (n) {
ans[cnt++] = n % ;
n /= ;
}
for (int i = cnt; i <= len; i++)
ans[i] = ;
ans[len]++;
for (int i = ; i <= len/; i++)
ans[i] = ans[len-i+];
for (int i = ; i <= len; i++)
printf("%d", ans[i]);
printf("\n");
}
return ;
}
 

UVa 12050 - Palindrome Numbers (回文数)的更多相关文章

  1. POJ2402 Palindrome Numbers 回文数

    题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...

  2. Uva - 12050 Palindrome Numbers【数论】

    题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...

  3. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  4. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  5. Leetcode 3——Palindrome Number(回文数)

    Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...

  6. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  7. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  8. [LeetCode]9. Palindrome Number回文数

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  9. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

随机推荐

  1. 在非NDK编译条件下使用Android Log函数

    解决的需求 有些时候不能在NDK环境编译,或者使用NDK编译会颇费周折,然后又想使用Android系统自带的Log类方法,那么我们就可以使用dlopen来实现我们的目的.比如在OpenCV中添加And ...

  2. Ubuntu 1910安装Openshift 4.0单机版 (CRC)

    Openshift默认可以在CentOS等RHEL系的发行版上安装. 本文转述一下如何在Ubuntu 1910上安装Openshift4.0单机版(CRC). 原文请参考:  https://gith ...

  3. System.Text.Json 自定义Converter实现时间转换

    Newtonsoft.Json与System.Text.Json区别 在 Newtonsoft.Json中可以使用例如 .AddJsonOptions(options => { options. ...

  4. 数据分析----天气预报走向(pygal)

    #!usr/bin/env python #-*- coding:utf-8 _*- """ @author:Administrator @file: 可视化天气预报.p ...

  5. Sercet sharing

    Secret Sharing Shamir门限 条件: \(0<k\leq n<p\) \(S<p,p\)是素数 Lagrange插值公式 \[ f(x)=\sum^{k}_{j=1 ...

  6. 安装NFS到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 软件版本:无 硬件要求:无 安装过程 1.配置YUM源 [root@localhost ~]# rpm -i https ...

  7. IDEA最新注册码 (亲测有效,可激活至 2089 年~)

    申明:本教程 IntelliJ IDEA 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除. 分享IDEA最新注册码 (亲测有效,可激活至 2089 年~) 注意 本 ...

  8. Spark调优指南

    Spark相关问题 Spark比MR快的原因? 1) Spark的计算结果可以放入内存,支持基于内存的迭代,MR不支持. 2) Spark有DAG有向无环图,可以实现pipeline的计算模式. 3) ...

  9. NAS之NFS/CIFS

    NAS之NFS 为集群中的 Web Server 配置后端存储 NFS:Network File System 网络文件系统,Unix系统之间共享文件的一种协议NFS 的客户端主要为Linux支持多节 ...

  10. Freefilesync-文件夹自动同步

    在企业的相关设置中,若两台物理机,主副之间需要做到文件同步,可以推荐使用Freefilesync作为自动同步设置 话不多说,直接搞机 开始设置好文件比对-点击红色漏斗设置(比较/同步) 点击确定 手动 ...