ural 1123
找大于等于原数的最小回文数字 代码比较烂...........
#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的更多相关文章
- BZOJ 1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1030 Solved: 440[Submit][Status] ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 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 ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- Red Hat Enterprise Linux 5安装序列号
为了保证安装的组件和订阅相匹配,红帽企业 Linux 5 需要输入一个安装号.它被用来配置安装程序来提供正确的软件包.安装号码包含在你的订阅里. 如果您没有输入安装号码,只有核心服务器或 Deskto ...
- 新年第一次分享sqlserver技术
走向DBA[MSSQL篇] - 从SQL语句的角度提高数据库的访问性能 最近公司来一个非常虎的DBA,10几年的经验,这里就称之为蔡老师吧,在征得我们蔡老同意的前提下 ,我们来分享一下蔡老给我们带来的 ...
- mount loop最大数的调整
mount: could not find any free loop device vi /etc/modules.conf Add "options loop max_loop=64&q ...
- 第六十六篇、OC_Sqlite数据库操作
#import <Foundation/Foundation.h> #import <sqlite3.h> #define kFilename @"data.sqli ...
- 转:ASP.NET中的SESSION实现与操作方法
在ASP.NET中,状态的保持方法大致有:ApplicationState,SessionState,Cookie,配置文件,缓存. ApplicationState 的典型应用如存储全局数据. Se ...
- nginx编译
先下载openssl.pcre.zlib安装:然后找个上传模块nginx-upload-module-2.2添加到nginx上. root@liuhan888:~# mkdir nginxroot@l ...
- Windows Phone 8.1 列表控件(1):基本
说到 List 控件,Windows Phone 8.1 上推荐使用的是 ListView 和 GridView. 而这两个控件实在太多东西可讲了,于是分成三篇来讲: (1)基本 (2)分组数据 (3 ...
- html5 的<audio> 音频 audio的“坑”
<audio>标签是html5的一个非常有意义的特性.告别的flash的时代.它的属性有: autoplay:音频就绪后马上播放 controls:出现该属性,向用户显示播放的控件. lo ...
- C# winfrom中的布局 控件Anchor和Dock的区别
c#中的布局问题 http://hi.baidu.com/whzpower/item/57e3179cca21e1cab725317a
- ajax post 时 form数据serialize()
$.post(UrlAddData, $(".AddForm").serialize(), function (data) { if (data.result) { $.liger ...