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 ;
}
 

最新文章

  1. h5手机端下拉选择城市
  2. js基础-表单验证和提交
  3. c# 当引用类型作为方法的参数
  4. 以下是关于ASP.NET中保存各种信息的对象的比较,理解这些对象的原理,对制作完善的程序来说是相当有必要的(摘至互联网,并非原创--xukunping)
  5. border-box
  6. shiyan2
  7. 图解IoC 依赖注入
  8. WebSphere常用设置
  9. Query classification; understanding user intent
  10. 自己实现的android树控件,android TreeView
  11. CentOS 6.5下搭建NFS文件服务器
  12. jQuery 表单验证插件——Validation(基础)
  13. HDU ACM 1066 Last non-zero Digit in N!
  14. PostScript学习:另一种缩写为PS的技术
  15. 个人作业(3)----个人总结(Alpha阶段)
  16. Spring Boot 2.x 综合示例-整合thymeleaf、mybatis、shiro、logging、cache开发一个文章发布管理系统
  17. key单片机按键抖动
  18. C++编写 动态链接库dll 和 调用dll
  19. Sql Server 增加字段、修改字段、修改类型、修改默认值
  20. Windows server2012 IIs 8 自定义日志记录

热门文章

  1. clr via c# clr寄宿和AppDomain (一)
  2. 二进制、十六进制理解及int类型二进制存储方式
  3. centos 记录所有用户操作命令的脚本
  4. HDFS基本命令fs的使用操作
  5. hive内置方法一览
  6. Ubuntu安装软件时报 Unable to acquire the dpkg frontend lock解决方案
  7. 正则表达式中的exec()方法
  8. jdk8中接口中的特性
  9. eclipse一直不停building workplace
  10. 动态加载js文件是异步的