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个回文数字

不会写此题啊,膜一下网上大佬代码,没有全看懂,只看懂一部分,没有注释--_--!,他日再破吧。。。

AC代码

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <iostream>
  6. #include <sstream>
  7. #include <queue>
  8. #include <vector>
  9. #include <algorithm>
  10. #define maxn 3000
  11. using namespace std;
  12. typedef long long ll;
  13. ll num[maxn];
  14. int n, ans[maxn];
  15.  
  16. void init()
  17. {
  18. num[] = , num[] = num[] = ;
  19. for (int i = ; i < ; i += )
  20. num[i] = num[i+] = num[i-] * ; //预处理i位的回文数的个数,9,9,90,90,900....
  21. }
  22.  
  23. int main()
  24. {
  25. init();
  26. while (scanf("%d", &n) && n)
  27. {
  28. int len = ;
  29. while (n > num[len])
  30. {
  31. n -= num[len]; //判断第n个回文数字有多少位,len
  32. len++;
  33. }
  34. n--;
  35.  
  36. int cnt = len / + ; //写出回文数字后半边
  37. while (n)
  38. {
  39. ans[cnt++] = n % ;
  40. n /= ;
  41. }
  42. for (int i = cnt; i <= len; i++)
  43. ans[i] = ;
  44. ans[len]++;
  45.  
  46. for (int i = ; i <= len/; i++)
  47. ans[i] = ans[len-i+]; //前半边由后半边复制过来
  48. for (int i = ; i <= len; i++)
  49. printf("%d", ans[i]);
  50. printf("\n");
  51. }
  52. return ;
  53. }

2017ecjtu-summer training #1 UVA 12050的更多相关文章

  1. Uva - 12050 Palindrome Numbers【数论】

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

  2. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  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. 2017ecjtu-summer training #1 UVA 10399

    It has been said that a watch that is stopped keeps better time than one that loses 1 second per day ...

  5. UVa - 12050

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

  6. Palindrome Numbers UVA - 12050(第几个回文数)

    长度为k的回文串个数有9*10^(k-1) #include <iostream> #include <cstdio> #include <sstream> #in ...

  7. UVa - 12050 Palindrome Numbers (二分)

    Solve the equation: p ∗ e −x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x 2 + u = 0 where 0 ≤ x ≤ ...

  8. UVa 12050 - Palindrome Numbers (回文数)

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

  9. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

随机推荐

  1. Hosts文件实际应用 配置内部服务器提高访问效率和速度

    一 hosts文件的作用和介绍 https://jingyan.baidu.com/article/335530da45485e19cb41c3d6.html https://www.cnblogs. ...

  2. ListView用法总结C#

    ListView是个较为复杂的控件     网上教程写的很乱,C#中文资料太匮乏了,小白叔叔觉得有必要自己出一份了. http://blog.sina.com.cn/s/blog_43eb83b901 ...

  3. ES6 对象的扩展(上)

    属性的简介表示法 允许直接写入变量和函数作为对象的属性和方法,这样的书写更简洁. function f( x, y ) { return { x, y }; } // 等同于 function f( ...

  4. 在ubuntu上安装pyenv出现的问题

    1.安装完pyenv时,并没有出现问题.但在安装python3.6.1时报错: ERROR: The Python ssl extension was not compiled. Missing th ...

  5. 鸟哥的linux私房菜学习-(五)Linux系统的在线求助man page与info page

    1.man page man是manual(操作说明)的简写啦!只要下达:『man date』 马上就会有清楚的说明出现在你面前喔!如下所示: 进入man命令的功能后,你可以按下『空格键』往下翻页,可 ...

  6. Head First设计模式之模板方法模式

    一.定义 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中,使得子类可以不改变算法结构的情况下,重定义该算法中的某些特定步骤. 比较通俗的说法,子类决定如何实现算法中的某些步骤,比如两个一连串 ...

  7. tensorflow mnist read_data_sets fails

    下载处理mnist数据时出现如下错误 VisibleDeprecationWarning: converting an array with ndim > 0 to an index will ...

  8. 2017-07-20聊聊《C#本质论》

    第一次接触<C#本质论>是在这个链接.那时候刚学写C#,而且它的语言风格深深吸引了我,噢对了还有它强大的IDE--VS.这个链接里的书确实不错.文中提到: 虽然这三本书都是外国原著的,但是 ...

  9. 实体处理模块IEntityModule

    在2015年7月16日,XCode新增了实体处理模块IEntityModule,用于拦截实体对象添删改操作. 该接口参考IHttpModule设计理念,横切在实体对象的关键生命周期之中,以达到多实体类 ...

  10. Windows下安装Selenium

    安装python,建议在官网下载python3以上的版本 安装easy_install,找度娘 安装selenium,在命令行窗口下输入:pip install -U selenium 下载chrom ...