F - Palindrometer

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

While driving the other day, John looked down at his odometer, and it read 100000. John was pretty excited about that. But, just one mile further, the odometer read 100001, and John was REALLY excited! You see, John loves palindromes - things that read the same way forwards and backwards. So, given any odometer reading, what is the least number of miles John must drive before the odometer reading is a palindrome? For John, every odometer digit counts. If the odometer reading was 000121, he wouldn't consider that a palindrome.

Input

There will be several test cases in the input. Each test case will consist of an odometer reading on its own line. Each odometer reading will be from 2 to 9 digits long. The odometer in question has the number of digits given in the input so, if the input is 00456, the odometer has 5 digits. There will be no spaces in the input, and no blank lines between input sets. The input will end with a line with a single 0.

Output

For each test case, output the minimum number of miles John must drive before the odometer reading is a palindrome. This may be 0 if the number is already a palindrome. Output each integer on its own line, with no extra spaces and no blank lines between outputs.

Sample Input

100000
100001
000121
00456
0

Sample Output

1
0
979
44
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1010
const int inf=0x7fffffff; //无限大
int step;
int check(string s)
{
//cout<<s<<" "<<step<<endl;
for(int i=;i<s.size();i++)
{
if(s[i]!=s[s.size()--i])
return ;
}
return ;
}
int pingfang(int x,int y)
{
if(y==)
return ;
int ans=;
for(int i=;i<=y;i++)
{
ans*=x;
}
return ans;
}
int main()
{
string s;
while(cin>>s)
{
string s1="";
if(s==s1)
break;
ll num=;
step=;
int len=;
while(!check(s))
{
if(s[s.size()--len]==s[len])
{
len++;
continue;
}
else if(s[s.size()--len]<s[len])
{
step+=((int)(s[len]-'')-(int)(s[s.size()--len]-''))*pingfang(,len);
s[s.size()--len]=s[len];
len++;
}
else
{
step+=((int)(s[len]-'')+-(int)(s[s.size()--len]-''))*pingfang(,len);
s[s.size()--len]=s[len];
for(int i=len+;i<s.size();i++)
{
if(s[s.size()--i]=='')
{
s[s.size()--i]='';
}
else
{
s[s.size()--i]++;
break;
}
} len=;
}
}
cout<<step<<endl;
}
return ;
}

UVALive 4868 Palindrometer 暴力的更多相关文章

  1. UVaLive 4868 Palindrometer (暴力 / 构造)

    题意: 给定一个固定长度的字符串, 字符串是一个含有前导0的数字, 问这个数字加上多少能构成一个回文字符串. 分析: 其实这题有很多种方法, 方法12是我做完后看别人代码总结的, 方法3是我当时想的一 ...

  2. UVALive 5107 dfs暴力搜索

    题目链接:A hard Aoshu Problem DES:给三个字符串,包含的字符是A-E范围内的.长度都不超过8.每个字符可以而且只可以匹配一个数字.两个字符不能匹配相同的数字.前两个式子之间可以 ...

  3. UVALive 5844 dfs暴力搜索

    题目链接:UVAive 5844 Leet DES:大意是给出两个字符串.第一个字符串里的字符可以由1-k个字符代替.问这两个字符串是不是相等.因为1<=k<=3.而且第一个字符串长度小于 ...

  4. UVaLive 6854 City (暴力)

    题意:给定一个 n*m 的矩阵,表示有多少条道路与它相连,其中有一个-1,表示未知,道路只能横着和竖着,求-1处的值. 析:根据题意可知,一个点,与其他周围的四个点都可能相连的,也就是说肯定有共用道路 ...

  5. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  6. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...

  8. UVaLive 6623 Battle for Silver (最大值,暴力)

    题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少. 析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力 ...

  9. UVaLive 6855 Banks (水题,暴力)

    题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了... ...

随机推荐

  1. aarch64_g1

    GAPDoc-1.5.1-12.fc26.noarch.rpm 2017-02-14 07:37 1.0M fedora Mirroring Project GAPDoc-latex-1.5.1-12 ...

  2. C# 读取指定文件夹下所有文件

    #region 读取文件 //返回指定目录中的文件的名称(绝对路径) string[] files = System.IO.Directory.GetFiles(@"D:\Test" ...

  3. 数论-求n以内的质数

    一.埃拉托斯特尼筛法 名字很高大上,然而并没有什么卵用…… 思路: 在把<=√n的质数所有的<=n的倍数剔除,剩下的就都是质数了,很容易理解…… 复杂度O(nloglogn) #inclu ...

  4. spring学习之一概念

    概念 1.是开源的轻量级框架 2.是一站式框架,就是说在java ee的三层结构中,每一层它都提供了不同的解决技术 web层:springMVC servoce层:spring IOC ,控制反转,通 ...

  5. MongoDB官方文档结构

    本文展示MongoDB 3.6.4.0的官方Server文档的结构图——一眼可见完整的知识脉络图.不过,MongoDB除了Server的文档外,还有DRIVERS.CLOUD.TOOLS.DUIDES ...

  6. linux java配置

    1.java配置 配置环境变量在/etc/profile下增加# set Java environmentJAVA_HOME=/usr/share/jdk1.6.0_43PATH=$JAVA_HOME ...

  7. wpf设置某容器透明,而不应用到容器的子元素的方法

    以Border打比方: <Border.Background> <SolidColorBrush Opacity="0.4" Color="Black& ...

  8. Python学习笔记:一手漂亮的Python函数

    使用类和函数定义模型 函数是抽象和封装的基本方法之一 重构函数  -- 命名合理  -- 具有单一功能  -- 包含文档注释  -- 返回一个值  -- 代码不超过 50 行  -- 幂等函数,尽可能 ...

  9. Elasticsearch安全问题

    本节内容: 背景 修改默认的 Elasticsearch 集群名称 不要暴露 Elasticsearch 在公网上 不要以 root 身份运行 Elasticsearch 定期对 Elasticsea ...

  10. Java学习(Map接口)

    一.概述: 我们通过查看Map接口描述,发现Map接口下的集合与Collection接口下的集合,它们存储数据的形式不同,如下图. 1. Collection中的集合,元素是孤立存在的(理解为单身), ...