找大于等于原数的最小回文数字  代码比较烂...........

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
char s[2010];
int main()
{
scanf("%s",s);
int len = strlen(s);
int l = 0, r = len - 1;
int flag = 0;
int T = 0;
while(r>=l)
{
if(r - l > 1)
{
if(s[l] < s[r])
flag = 1;
s[r] = s[l];
}
else if(r - l == 1)
{
if(s[r] > s[l])
s[l] = s[r];
else if(s[l] > s[r])
{
s[r] = s[l];
}
else
{
if(flag)
{
if(s[r] != '9')
{
s[r] += 1;
s[l] += 1;
}
else
while(1)
{
if(s[r] == '9')
{
s[r] = '0';
s[l] = '0';
r++;
l--;
}
else
{
s[r] += 1;
s[l] += 1;
T = 1;
break;
}
}
}
}
}
else
{
if(flag)
{
if(s[r] != '9')
s[r] += 1;
else
while(1)
{
if(s[r] == '9')
{
s[r] = '0';
s[l] = '0';
r--;
l++;
}
else
{
s[r] += 1;
s[l] += 1;
break;
}
}
}
}
if(T)
break;
l++;
r--;
}
puts(s);
return 0;
}

ural 1123的更多相关文章

  1. BZOJ 1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1030  Solved: 440[Submit][Status] ...

  2. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  3. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  4. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  5. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  6. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  7. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  8. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  9. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

随机推荐

  1. unity3d游戏无法部署到windows phone8手机上的解决方法

    今天搞了个unity3d游戏,准备部署到自己的lumia 920上,数据线连接正常,操作正常,但是“build”以后,始终无法部署到手机上,也没有在选择的目录下生产任何相关文件.(你的系统必须是win ...

  2. Ajax之数据连接信息捕获

      connDB.properties: DB_CLASS_NAME=com.mysql.jdbc.Driver DB_URL=jdbc:mysql://127.0.0.1:3306/db_datab ...

  3. NDIS IM 驱动那些事情

    最近不知道为什么开始学习windows NDIS驱动开发,用的是寒江独钓的例子,其实他的改的代码也就一点点,说的有用的东西也就那么多,不过还是感谢他出了这么一本书,不然这真的就没有一本稍微好一点的书籍 ...

  4. Unity User Group 北京站图文报道:《Unity3D VR游戏与应用开发》

    很高兴,能有机会回报Unity技术社区:我和雨松MOMO担任UUG北京站的负责人, 组织Unity技术交流和分享活动. 本次北京UUG活动场地–微软大厦 成功的UUG离不开默默无闻的付出:提前2小时到 ...

  5. [Bootstrap]概述

    ——1.html,css,javascript框架                ——2.一般开发响应式布局或者移动优先的项目可以优先考虑 优点 1.css开发版本(可以直接上手)和源码版本(可根据l ...

  6. jQuery 日历控件 FullCalendar 初识

    最近有个日程管理的需求,就学习了一下 FullCalendar 控件的一些基本知识,本文不是详细介绍该控件的 API 的文档,而是记录本人使用过程中的一些学习情况. 先看一下效果图  月/周/日视图 ...

  7. C# 代理HTTP请求

    目的: 应该有不少人需要去某些网站不停爬取数据,有时会使用HTTPRequest一直请求某个网站的某个网址.有的网站比如 QQ空间,赶集网(这是我测试的网站),不停刷新会提醒你的账号异常,可能会查封你 ...

  8. 深度探索C++对象模型读书笔记(2)

    以下测试平台均为vs 2012 指向Data Member的指针测试(1) #include <stdio.h> class Base1 { public: int val1; int v ...

  9. SAP校园招聘笔试

    一直就向往着SAP公司,终于,有幸今天参加了SAP校园招聘的笔试.下面我就来简单说说这个笔试的内容. 笔试分为两大部分,一部分是逻辑题,就是些什么阅读分析计算balabala的一堆,是全英文的.另外一 ...

  10. SystemFile

    header('Content-Type:text/html; charset = utf-8'); 1. echo "<pre/>";echo __FILE__.&q ...