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 ...
随机推荐
- [转]使用C#开发ActiveX控件全攻略
前言: 这段时间因为工作的需要,研究了一下ActiveX控件.总结如下: 先说说ActiveX的基本概念. 根据微软权威的软件开发指南MSDN(Microsoft Developer Network) ...
- ACM竞赛之输入输出(以C与C++为例)
本文转自互联网,内容.排版有修正. 欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju G ...
- 网络营销相关缩写名称CPM CPT CPC CPA CPS SEM SEO解析
网络营销相关缩写名称CPM CPT CPC CPA CPS SEM SEO解析 CPM CPT CPC CPA CPS SEM SEO在网络营销中是什么意思?SEO和SEM的区别是? CPM(Cost ...
- centos上安装python3.6
安装python3.6可能使用的依赖 # yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sql ...
- MemcacheQ安装
一.memcacheq介绍 特性: 1.简单易用 2.处理速度快 3.多条队列 4.并发性能好 5.与memcache的协议兼容 6.在zend framework中使用方便 memcacheq依赖于 ...
- jquery插件--问题类(新增&&删除)简易版
HTML: <!doctype html> <head> <meta charset="utf-8" /> <script src=&qu ...
- Python3基础 list remove 删除元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Oracle和MySQL的对比
一.概述 1.1 Oracle 1.1.1 优点 开放性:Oracle 能所有主流平台上运行(包括 windows)完全支持所有工业标准采用完全开放策略使客户选择适合解决方案对开发商全力支持: 可伸缩 ...
- Vue开发中的中央事件总线
在Vue开发中会遇到大量的组件之间共享数据的情形,针对不同的情形,Vue有相对应的解决方案.比如,父组件向子组件传值可以使用props,复杂项目中不同模块之间传值可以使用Vuex.但是,对于一些简单的 ...
- [IDEA插件] - 一个不错的插件
今天看到微信平台一篇推送IDEA插件的文章继而下载了个插件看了下. 名字叫做codehelper.generator codehelper.generator http://plugins.jetbr ...