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 ...
随机推荐
- Impala与Hive的比较
1. Impala架构 Impala是Cloudera在受到Google的Dremel启发下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的Hive+MapReduce批 ...
- MyBatis学习笔记(八)——Mybatis3.x与Spring4.x整合
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn arc ...
- Hive 大数据倾斜总结
在做Shuffle阶段的优化过程中,遇 到了数据倾斜的问题,造成了对一些情况下优化效果不明显.主要是因为在Job完成后的所得到的Counters是整个Job的总和,优化是基于这些 Counters得出 ...
- Spring 问题总结
Spring问答Top 25:http://www.importnew.com/15851.html [Java面试五]Spring总结以及在面试中的一些问题.:http://www.cnblogs. ...
- Oracle查询session连接数和inactive以及 概要文件IDLE_TIME限制用户最大空闲连接时间
-----############oracle会话和进程################----------------查询会话总数select count(*) from v$session;--查 ...
- SpringMVC Spring MyBatis 框架整合 Annotation MavenProject
项目结构目录 pom.xml jar包管理 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
- Centos下使用php调用shell脚本
我们在实际项目中或许会遇到php调用shell脚本的需求.下面就用简单案例在Centos环境下实践 准备 查看php.ini中配置是否打开安全模式 //php.ini safe_mode = //这个 ...
- 20145118《Java程序设计》 第7周学习总结
20145118<Java程序设计> 第7周学习总结 教材学习内容总结 本周学习内容为第十三章,以下为教材内容重点总结: 1.格林威治标准时间简称GMT时间. 2.java.util.Da ...
- 20145304 Exp6 信息搜集与漏洞扫描
20145304 Exp6 信息搜集与漏洞扫描 实验后回答问题 (1)哪些组织负责DNS,IP的管理. NSI负责Internet顶级域名系统的注册.协调与维护,IAIA负责Internet的地址资源 ...
- 20145310 Exp7 网络欺诈技术防范
实验后回答问题 (1)通常在什么场景下容易受到DNS spoof攻击 局域网内最容易遭受攻击.通过DNS欺骗就可以轻松地将网址转到钓鱼网站.而我们平时最常用的局域网应该就是公共热点吧,特别是有的地方的 ...