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. leetcode--js--Two Sum

    问题描述: 给定一个整数数列,找出其中和为特定值的那两个数. 你可以假设每个输入都只会有一种答案,同样的元素不能被重用. 示例: 给定 nums = [2, 7, 11, 15], target = ...

  2. js this是什么?[多次书写]

    前言 以前的时候,我写了一个关于js this的博客,写的非常复杂,分析了各种情况. 现在我想简化. 如果你有后台基础,专门去理解过this,那么请忘记. 这东西是有口诀的: 在方法中,this 表示 ...

  3. .NET Core 3 Web Api Cors fetch 一直 307 Temporary Redirect

    .NET Core 3 Web Api Cors fetch 一直 307 Temporary Redirect 继上一篇 .net core 3 web api jwt 一直 401 为添加JWT- ...

  4. 11.Android-Xml读写

    android中写XML时,需要用到XmlSerializer类 解析XML时,则需要用到XmlPullParser类 1.XmlSerializer类介绍 通过Xml.newSerializer() ...

  5. Android中调用另一个Activity并返回结果-以模拟选择头像功能为例

    场景 Android中点击按钮启动另一个Activity以及Activity之间传值: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detail ...

  6. \n不换行

    \n在js中表示换行,<br/>在html中表示换行,所以如果在设置innerHtml值时使用  \n  ,那么在页面上并不会显示换行,而在设置innerText值时使用  \n  就会显 ...

  7. CentOS7.6安装MySQL8.0(图文详细篇)

    目录 一.安装前准备 二.安装MySQL 三.设置远程登录 四.安装问题解决 五.设置MySQL开机自启 一.安装前准备 1.在官网下载MySQL安装包(注意下载的安装包类型)  2.查看是否安装ma ...

  8. 展讯平台uboot启动流程

    启动流程 1. Stage1 start.S代码结构 u-boot的stage1代码通常放在start.S文件中,用汇编语言,主要实现功能如下:  (1) 定义入口: 该工作通过修改连接器脚本来完成. ...

  9. Function and Function

    If we define , do you know what function  means? Actually,  calculates the total number of enclosed ...

  10. Android开发第一天---AndroidStudio的安装和第一个安卓开发

    今天已经是开始学习Android的第二天,我居然才把AndroidStudio开发环境安装并配置好,我只能说“我太难了”,下了好几个版本,终于找到了一个合适的,得出一个结论外国的东西是真的不太好用啊, ...