题意:给定i,输出第i个回文数字。

分析:1,2,3,4,……,9------------------------------------------------------------------------------------------9个

   11,12,13,14,……,19-------------------------------------------------------------------------------------9个

   101,111,121,131,141,151,161,171,181,191,202,212,222,232,……,979,989,999-------------------------------90个

   1001,1111,1221,1331,1441,……,9889,9999----------------------------------------------------------------90个

   10001,10101,10201,10301,……,99899,99999--------------------------------------------------------------900个

   规律是把回文串一分为二看,例如第四行,前两个数字是从10到99,共90个数字。而第三行也是从10到99,区别在于,需要去掉最后一位再反转,才是另一半(后两个数字)。

思路:先确定i所对应的回文数字的位数,再确定具体值。

 #include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
#define pr(x) cout << #x << " : " << x << " "
#define prln(x) cout << #x << " : " << x << endl
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-;
const int dx[] = {, , -, };
const int dy[] = {-, , , };
const ll MOD = 1e9 + ;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
ll a[];
void init()
{
ll tmp = ll();
for(int i = ; i < ; i += )
{
a[i] = a[i - ] = tmp;
tmp *= ll();
}
}
ll POW(ll x)
{
ll w = ;
for(ll i = ; i <= x; ++i)
w *= ll();
return w;
}
int main()
{
init();
int n;
while(scanf("%d", &n) == && n)
{
int cnt = ;
while(n > a[cnt])
{
n -= a[cnt];
++cnt;
}
if(cnt == )
{
printf("%d\n", n);
continue;
}
else if(cnt == )
{
printf("%d%d\n", n, n);
continue;
}
else
{
int tmp = cnt / ;
char str[];
memset(str, , sizeof str);
ll ans = POW(ll(cnt / )) + ll(n - );
sprintf(str, "%lld", ans);//把数字变为指定格式的字符串
printf("%s", str);
string s = string(str);
int len = s.size();
if(cnt % == ) s.resize(len - );
reverse(s.begin(), s.end());
printf("%s\n", s.c_str());
}
}
return ;
}

   

UVALive 2889(回文数字)的更多相关文章

  1. [LeetCode] Palindrome Number 验证回文数字

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  2. javascript 实现一个回文数字

    写一个方法,让"1234"变成回文数字“1234321”,就是顺着读和倒着读都是一样的:注:不让用reverse()方法: function palindrome(str){ va ...

  3. Java 简单算法--打印回文数字

    package cn.magicdu.algorithm; public class CircleNumber { public static void main(String[] args) { f ...

  4. [蓝桥杯]PREV-21.历届试题_回文数字

    问题描述 观察数字:, 都有一个共同的特征,无论从左到右读还是从右向左读,都是相同的.这样的数字叫做:回文数字. 本题要求你找到一些5位或6位的十进制数字.满足如下要求: 该数字的各个数位之和等于输入 ...

  5. 【蓝桥杯】PREV-21 回文数字

    题目链接:http://lx.lanqiao.org/problem.page? gpid=T113   历届试题 回文数字   时间限制:1.0s   内存限制:256.0MB      问题描写叙 ...

  6. LeetCode 9 Palindrome Number(回文数字判断)

    Long Time No See !   题目链接https://leetcode.com/problems/palindrome-number/?tab=Description   首先确定该数字的 ...

  7. 算法笔记_181:历届试题 回文数字(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 观察数字:12321,123321 都有一个共同的特征,无论从左到右读还是从右向左读,都是相同的.这样的数字叫做:回文数字. 本题要求你找 ...

  8. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  9. Java小程序之回文数字

    题目:一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. 下面是代码: package test; public class BackNum { public st ...

随机推荐

  1. Python的包管理工具Pip

    接触了Ruby,发现它有个包管理工具RubyGem非常好用,而且有非常完备的文档系统http://rdoc.info 发现Python下也有相同的工具,包含easy_install和Pip.只是,我没 ...

  2. w3cmark前端精彩博文周报 10.20-10.27

    w3cmark 官方Q群 145423956 | 官方微博 @w3cmark 自从最近微博屏蔽了我的站点域名,就很懒了.毕竟和不爽,一个纯技术站点还被认为不安全链接,还申诉无门,那些所谓的客服都是自动 ...

  3. Android - 软件自动更新的实现

    转自:http://blog.csdn.net/wwj_748/article/details/8195565 接触到一个很实用的技术,那就是软件自动更新.一般开发者是通过自行在应用平台添加更新版本的 ...

  4. JAVA编程规则

    本附录包含了大量有用的建议,帮助大家进行低级程序设计,并提供了代码编写的一般性指导: (1) 类名首字母应该大写.字段.方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在 ...

  5. [MEAN Stack] First API -- 6. Using Express route instance

    For server.js, we update the code by using route instance. By using this, we can remove some duplica ...

  6. MySQL Troubleshoting:Waiting on query cache mutex 腾讯数据库工程师:幕南风

    http://blog.itpub.net/26515977/viewspace-1208188/           今天被MySQL Query Cache 炕了.线上大量 Waiting on ...

  7. leetcode -- Search for a Range (TODO)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  8. Spark_Api_图解

  9. TRF7960天线参数试验

    CA1焊47pF就好了,不大用调,主要调CA2的值 图中CA2焊100pF时,读卡距离2cm左右 27pF                3.5cm左右 不焊 4cm左右 47pF 5cm左右 现在手 ...

  10. E - Trees on the level

     Trees on the level  Background Trees are fundamental in many branches of computer science. Current ...