题意:比给出的数大的最小回文数。

先用前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的更多相关文章

  1. SPOJ:The Next Palindrome(贪心&思维)

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  2. bzoj 3768: spoj 4660 Binary palindrome二进制回文串

    Description 给定k个长度不超过L的01串,求有多少长度为n的01串S满足: 1.该串是回文串 2.该串不存在两个不重叠的子串,在给定的k个串中. 即不存在a<=b<c<= ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. SPOJ #5 The Next Palindrome

    "not more than 1000000 digits" means an efficient in-place solution is needed. My first so ...

  5. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  6. 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 ...

  7. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  8. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  9. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

随机推荐

  1. 测试开发-PC客户端测试要点

      一级测试点 二级测试点 安装测试 首次安装(exe和msi格式的不同) 安装程序权限检查 软件安装包的描述和属性信息 静默安装和非静默安装测试 有UAC安装.无UAC安装 联网安装.断网安装 对必 ...

  2. 如何在Linux环境下通过uwgsi部署Python服务

    部署python程序时常常会遇到同一台服务器上2.x和3.x共存的情况,不同应用需要使用不用的python版本,使用virtualenv创建虚拟环境能很好地解决这一问题. 首先,需要在服务器上安装vi ...

  3. web前端----html基础

    一.初始html 1.web服务本质 import socket sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.bind((&q ...

  4. 贪婪算法(Greedy Algorithm)

    Greedy Algorithm <数据结构与算法--C语言描述> 图论涉及的三个贪婪算法 Dijkstra 算法 Prim 算法 Kruskal 算法 Greedy 经典问题:coin ...

  5. 08: CORS实现跨域请求

    目录: 1.1 cors跨域请求介绍 1.2 使用tornado实现 复杂请求 1.3 Django中使用django-cors-headers解决跨域问题 1.1 cors跨域请求介绍返回顶部 1. ...

  6. 04: Form 验证用户数据 & 生成html

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  7. 20145220韩旭飞《网络对抗》Exp8 Web基础

    20145220韩旭飞<网络对抗>Exp8 Web基础 Web前端:HTML基础 首先,我们的Web开发是基于Apache服务器进行的,所以对于Apache的基本操作我们是应该要掌握的,对 ...

  8. 20145303刘俊谦《网络攻防》Exp4 Msf基础

    20145303刘俊谦<网络攻防>Exp4 Msf基础 实验目标 • 掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路. • 一个主动攻击,如ms08_067: • 一 ...

  9. 20145312 《网络对抗》 Web安全基础实践

    20145312 <网络对抗> Web安全基础实践 问题回答 SQL注入攻击原理,如何防御 原理:攻击者在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,把SQL语句当做 ...

  10. SYSBIOS学习笔记---线程(Threads)

    在SYS/BIOS中,广义上指被处理器执行的任何独立的指令流.线程是一个能够调用一个函数或者中断服务程序的单点控制.在sysbios系统中一共有硬件中断(HWI).软件中断(SWI).任务(Task) ...