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 ...
随机推荐
- Android之图片窗口和大小调节
结构图: 基类: package ch.halcyon.squareprogressbar.example; import android.app.Activity; import android.a ...
- 基于DIV+ul+li实现的表格(多示例)
一个无序列表biaoge,前四个列表项我们赋予了类biaotou.因为这四个项是表格头部,应该与表格数据有所区别.所以单独赋予了类,可以方便控制.下面我们开始CSS代码的编写:由 www.169it. ...
- 从客户端中检测到有潜在危险的 request
如题,当遇到这种情况该怎么办呢? 通常情况下一下2种解决方案就可以解决问题了: 解决方案一: 在.aspx文件头中加入这句: <%@ Page validateReques ...
- (转)实战Memcached缓存系统(4)Memcached的CAS协议
1. 什么是CAS协议 很多中文的资料都不会告诉大家CAS的全称是什么,不过一定不要把CAS当作中国科学院(China Academy of Sciences)的缩写.Google.com一下,CAS ...
- FreeMarker-Built-ins for strings
http://freemarker.org/docs/ref_builtins_string.html Page Contents boolean cap_first capitalize chop_ ...
- 谈谈Nullable<T>的类型转换问题
本篇文章讨论可空值类型(Nullable<T>)的转换,却确地说是如何将一种类型的值对象转换成相应的可空值.这来源于今天我们的一个成员遇到的一个小问题,我经过一些整理写了这篇文章.虽然没有 ...
- 文件存储之-内存文件系统tmpfs
前言 我们都知道,对于单台服务器来说,除了 CPU ,内存就是我们存储数据最快的设备.如果可以把数据直接存储在内存中,对于性能的提升就不言而喻了.那么我们先来讲讲如何使用内存来存储文件. 首先,我们先 ...
- 好用的ssh工具oh-my-zsh / iterm2
The manual way 1. Clone the repository: git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...
- CentOS-6.3安装配置Nginx
安装说明 系统环境:CentOS-6.3软件:nginx-1.2.6.tar.gz安装方式:源码编译安装 安装位置:/usr/local/nginx 下载地址:http://nginx.org/en/ ...
- php判断服务器是否支持Gzip压缩功能
Gzip可以压缩网页大小从而达到加速打开网页的速度,目前主流的浏览器几乎都支持这个功能,但开启Gzip是需要服务器支持的,在这里我们简单的使用php来判断服务器是否支持Gzip功能. 新建一个php类 ...