spoj The Next Palindrome
题意:比给出的数大的最小回文数。
先用前n/2长对称到后面,如果没变大,在中间加1,进位,再对称。
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF; void work(string &str)
{
int bs=;
for(int i=;i<str.size()/;++i)
{
if(str[i]>str[str.size()--i])bs=;
else if(str[i]<str[str.size()--i])bs=-;
str[str.size()--i]=str[i];
}
if(bs<=)
{
int c=;
str[(str.size()-)/]+=;
for(int i=(str.size()-)/;i>=;--i)
{
str[i]+=c;
if(str[i]>'')str[i]='',c=;
else c=;
}
if(c)
{
str=""+str;
}
for(int i=;i<str.size()/;++i)
{
str[str.size()--i]=str[i];
}
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","w",stdout);
lon casenum;
cin>>casenum;
for(lon time=;time<=casenum;++time)
//for(;scanf("%d",&n)!=EOF;)
{
string str;
cin>>str;
work(str);
cout<<str<<endl;
}
return ;
}
spoj The Next Palindrome的更多相关文章
- SPOJ:The Next Palindrome(贪心&思维)
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- bzoj 3768: spoj 4660 Binary palindrome二进制回文串
Description 给定k个长度不超过L的01串,求有多少长度为n的01串S满足: 1.该串是回文串 2.该串不存在两个不重叠的子串,在给定的k个串中. 即不存在a<=b<c<= ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- SPOJ #5 The Next Palindrome
"not more than 1000000 digits" means an efficient in-place solution is needed. My first so ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
随机推荐
- 20145316许心远《网络对抗》EXP8 Web基础
实验后回答问题 什么是表单 来自百度百科的官方定义:表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. ...
- redis删除单个key和多个key,ssdb会落地导致重启redis无法清除缓存
redis删除单个key和多个key,ssdb会落地导致重启redis无法清除缓存,需要针对单个key进行删除 删除单个:del key 删除多个:redis-cli -a pass(密码) keys ...
- oracle中使用函数控制过程是否执行(结合job使用)
oracle中使用函数控制过程是否执行(结合job使用时候,循环时间不好写的时候,可以此种方法比较方便) CREATE OR REPLACE FUNCTION wsbs_pk_date_validat ...
- Finalize和Dispose的区别
https://www.cnblogs.com/Jessy/articles/2552839.html
- c++编程和c在思想上最大的差别
从正规的血统上来说,c++跟java一样是面向对象编程语言,而c是面向结构的编程语言.但是,在现实中,有大量的系统虽然用cpp编写,但是100%跟java一样,使用面向对象的几乎没有,绝大部分都是结合 ...
- JavaScript Image对象 / Tabel对象 / Select对象 / Form对象
JavaScript Image / Tabel / Select / Form 对象 版权声明:未经授权,严禁转载! Image 对象 Image 对象,代表 <img> 元素. < ...
- ArcThemALL!5.1:解压、脱壳、压缩样样精通
原文链接:http://www.ithome.com/html/soft/57033.htm ArcThemALL!软件主要功能: 1.支持压缩和解压功能,支持常用的7z.zip.cab.iso.ra ...
- linux内核分析 1、2章读书笔记
一.linux历史 20世纪60年代,MIT开发分时操作系统(Compatible TIme-Sharing System),支持30台终端访问主机: 1965年,Bell实验室.MIT.GE(通用电 ...
- 汽车OBD接口定义
汽车上的OBD-II接口(母): ELM327用到的引脚: 2: SAE-J1850 PWM和SAE-1850 VPW总线(+) 4. 车身地 5. 信号地 6. CAN high (ISO 157 ...
- noip 瑞士轮 - 归并
背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分冗长 ...