问题

给一个数k,给出第k个回文数  链接

题解

打表找规律,详见https://www.cnblogs.com/lfri/p/10459982.html,差别仅在于这里从1数起.

AC代码

#include<cstdio>
#include<iostream>
#include<string>
#include<sstream>
using namespace std; typedef long long LL; void solve(string str)
{
int len = str.length(); if (len == )
{
printf("%c\n", str[] - );
return;
} if (str[] == '')
{
if (str[] == '')
{
str[] = '';
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
else
{
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
}
else
{
str[] = str[] - ;
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
} void ToString(LL num, string& str)
{
stringstream ss;
ss << num;
ss >> str;
} string str;
LL num; int main()
{ while (cin >> num && num)
{
ToString(num + , str); //从1开始num要加一,从0开始不用
solve(str);
}
return ;
}

POJ2402 Palindrome Numbers第K个回文数——找规律的更多相关文章

  1. 9 Palindrome Number(判断是否为回文数Easy)

    题目意思:判断是否为回文数,不许使用额外空间 ps:一直不理解额外空间的意思,int能用吗 思路:1.比较头尾 2.翻转,越界问题需考虑 class Solution { public: bool i ...

  2. Lightoj1205——Palindromic Numbers(数位dp+回文数)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  3. 1046-第K回文数

    描述 回文数是这样一个正整数:它从左往右读和从右往左读是一样的.例如1,111,121,505都是回文数.将1到100,000,000内所有回文数按从小到达排序后,第k个回文数是多少呢? 输入 第一行 ...

  4. 求第N个回文数 模板

    备忘. /*看到n可以取到2*10^9.说明普通方法一个个暴力计算肯定会超时的,那打表呢?打表我们要先写个打表的代码,这里不提供.打完表观察数据,我们会发现数据其实是有规律的.完全不需要暴力的把所有数 ...

  5. POJ2402 Palindrome Numbers 回文数

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

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

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

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

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

  8. POJ 2402 Palindrome Numbers(LA 2889) 回文数

    POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...

  9. 【LeetCode】1400. 构造 K 个回文字符串 Construct K Palindrome Strings

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计奇数字符出现次数 日期 题目地址:https:// ...

随机推荐

  1. 20个Flutter实例视频教程-第08节: 保持页面状态

    博客地址: https://jspang.com/post/flutterDemo.html#toc-bb9 视频地址: https://www.bilibili.com/video/av397092 ...

  2. UVa 10213 How Many Pieces of Land ? (计算几何+大数)

    题意:一块圆形土地,在圆周上选n个点,然后两两连线,问把这块土地分成多少块? 析:这个题用的是欧拉公式,在平面图中,V-E+F=2,其中V是顶点数,E是边数,F是面数.对于这个题只要计算V和E就好. ...

  3. lua中文教程【高级知识】

    一.编译和运行和调试 1.lua和其他解释型语言一样,先转换成为中间码再执行 2.dofile和loadfile的区别:loadfile编译返回不执行,返回错误代码:dofile执行,返回错误信息 3 ...

  4. Android之打包签名

    一.什么的是打包? 打包就是根据签名和其他标识生成安装包. 二.什么是签名? 1.在android应用文件(apk)中保存的一个特别字符串 2.用来标识不同的应用开发者:开发者A,开发者B 3.一个应 ...

  5. ZOJ3321,ZOJ3317

    ZOJ3321 //there is at most one edge between two nodes. 因为这句话的局限性,又要满足环,那么一定是每个点度为2,然后为n节点的一个环 //#inc ...

  6. Spring Boot Autowirted注入找不到Bean对象解决方法

    报错:Consider defining a bean of type 'xxxxxxxxxxxxx' in your configuration 1. 你应该在 ApplyApplication 启 ...

  7. IP服务-4-HSRP,VRRP和GLBP

    HSRP(热备份路由器协议).VRRP(虚拟路由器冗余协议)和GLBP(网关负载均衡协议) 当主机只知道一个IP地址能够用来访问子网外部时,可能会出现一些问题,这些协议正好解决了这一隐患. HSRP允 ...

  8. Codeforces 1132G(关系转化树+dfn+线段树)

    要点 显然要滑动修改维护. 像通常的数列next关系一样建边(单调栈预处理),因为贪心所以是树,然后发现增删只会影响区间内的子(or父,看你连边方向行事)节点,于是使用dfs序建线段树. 为了正确地修 ...

  9. Gym - 101810E ACM International Collegiate Programming Contest (2018)

    bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #def ...

  10. 洛谷 P1031 均分纸牌

    P1031 均分纸牌 这道题告诉我们,对于实在想不出算法的题,可以大胆按照直觉用贪心,而且在考试中永远不要试着去证明贪心算法,因为非常难证,会浪费大量时间. (这就是你们都不去证的理由??) 这道题贪 ...