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 ...
随机推荐
- Linux命令(4):cat命令
1.作用:连接并显示指定的一个和多个文件的有关信息: 2.格式:cat [选项] 文件1 文件2 ... 其中文件1.文件2为要显示的多个文件: 3.常见参数: 4.使用实例: [youname@ww ...
- 初话C++模板【用自己的话,解释清楚这些】
用自己的话解释清楚C++的模板编程 模板编程是为了解决什么问题而出现的? 提高代码的重用性,提高代码的利用率. 泛型编程的一种实现. 模板的精神是: 类型参数化. 模板的实现 模板分为:函数模板.类模 ...
- C# 线程--第四线程实例
概述 在前面几节中和大家分享了线程的一些基础使用方法,本章结合之前的分享来编写一些日常开发中应用实例,和编写多线程时一些注意点.如大家有好的实例也欢迎分享.. 应用实例 应用:定时任务程序 场景:系统 ...
- CAF(C++ actor framework)使用随笔(unbecome与keep_behavior用法)
看usermanual(使用随笔一里面有)看到差不多一半的时候,这个keep_behavior与unbeacome的结合引起了我的注意.(这是为什么呢?) 因为它的示例代码写的太简单了!我真的没看太懂 ...
- 选择问题(选出第i个最小元素)
通过分治法解决的分析(还有其他方法解决选择问题如使用 堆) 1 同快速排序一样,对输入的数组进行递归分解 不同的是:快速排序会递归处理分解的两边,而选择问题只处理需要的一边 2 选择问题的期望时间代价 ...
- STAD Parameters
STAD related parameters: 1. stat/file -- define the file name of the actual STAD content – defaul ...
- 用一天的时间学习Java EE中的SSH框架
首先说明一下,本人目前主要从事.NET领域的工作,但对于C++.Java.OC等语言也略知一二,周末闲来无事,特花费一天的时间学习了一下Java中的SSH框架,希望把学习过程中的心得体会与园友们进行分 ...
- 利用TCP 客户端---->服务端 传送文件到指定路径,并返回一个友好的回馈
首先盲写的一个传输文件的方法,但测试发现了一个非常不容易发现的问题,这里先说明一下. 错误的代码如下: package com.TCP.java; import java.io.File; impor ...
- mysql 触发器,insert,auto字段竟然一样....
a 表的字段有id,uid,name,其中id是自增值, CREATE TRIGGER trigger_insert_productAFTER INSERT ON aFOR EACH ROWBEGIN ...
- spring heibernate 调用存储过程
一:参考网址 http://sunbin123.iteye.com/blog/1007556 二:示例 @Autowired @Qualifier("jdbcTemplate") ...