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. C#设计模式学习笔记:(22)备忘录模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/8176974.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第十个模式--备 ...

  2. springcloud 项目源码 微服务 分布式 Activiti6 工作流 vue.js html 跨域 前后分离

    1.代码生成器: [正反双向](单表.主表.明细表.树形表,快速开发利器)freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本.处理类.service等完整模块2. ...

  3. 挂号平台首页开发(UI组件部分)

    JQ插件模式开发UI组件 JQ插件开发方法: 1.$.extend() 扩展JQ(比较简单,功能略显不足) $.extend({ sayHello:function(){ console.log(&q ...

  4. mysql数据库批量执行sql文件对数据库进行操作【windows版本】

    起因: 因工作需要,在本机测试环境升级mysql数据库,需逐条执行mysql数据库的sql文件对数据库进行升级,因此找了些关于mysql的文章,对批量升级数据库所需的sql文件进行升级. 整理思路: ...

  5. layui table 表头和内容数据不能对齐

    个人博客 地址:http://www.wenhaofan.com/article/20181224153019 今天使用layui table方法渲染时出现了个莫名其妙的错误 正常情况table应该是 ...

  6. TCP/IP详解阅读记录----第二章 数据链路层

    1.以太网     以太网是当今TCP/IP采用的主要的局域网技术.它采用一种称作CSMA/CD的媒体接入方法,其意思是带冲突检测的载波侦听多路接入.它的速率为10Mb/s,地址为48bit. 2.I ...

  7. 简单的说说tippyjs的使用

    我们会接触到很多插件的使用,但是我们该如何的去使用呢,本人建议多学习英语,会对开发很有帮助的 为什么说是多去学习它,接下来我们就来说说: 当你没学习英语看到下面的官网是这样子的 当你会英语了,你就会觉 ...

  8. Binder 原理整理

    linux进程间通信方式 1. 管道 管道的实质是一个内核缓冲区,管道的作用正如其名,需要通信的两个进程在管道的两端,进程利用管道传递信息.管道对于管道两端的进程而言,就是一个文件,但是这个文件比较特 ...

  9. git签名设置

    作用:只区分不同开发人员的身份 一.项目级别/仓库级别:仅在当前本地库范围内有效 签名设置用户名(UserName)和邮箱(User@email),邮箱可以是任意邮箱(无效邮箱也可以) git con ...

  10. 怎样在GitHub上新建一个文件夹

    GitHub如何创建文件夹 创建新文件的时候名字后面加个斜杠(/)就可以了 点击新建文件,输入文件名的时候后面加上斜杠/就是创建了一个文件夹,没有斜杠就是创建了一个文 创建好后点提交 Commit n ...