codeforces 518A. Vitaly and Strings
1 second
256 megabytes
standard input
standard output
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English letters, string s is lexicographically smaller than string t. Vitaly wondered if there is such string that is lexicographically larger than string s and at the same is lexicographically smaller than string t. This string should also consist of lowercase English letters and have the length equal to the lengths of strings s and t.
Let's help Vitaly solve this easy problem!
The first line contains string s (1 ≤ |s| ≤ 100), consisting of lowercase English letters. Here, |s| denotes the length of the string.
The second line contains string t (|t| = |s|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings s and t are the same and string s is lexicographically less than string t.
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
a
c
b
aaa
zzz
kkk
abcdefg
abcdefh
No such string
String s = s1s2... sn is said to be lexicographically smaller than t = t1t2... tn, if there exists such i, that s1 = t1, s2 = t2, ... si - 1 = ti - 1, si < ti.
大意是找一个序列长度和s,t的长度相同,并且字典序在s之后,在t之前。
看了数据之后发现有点小坑。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cctype>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#define LL long long
#define PF(x) ((x)*(x))
#define LF(x) ((x)*PF(x)) using namespace std;
const int INF=<<-;
const int max9=1e9;
const int max6=1e6;
const int max3=1e3; int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
} int main()
{
char str1[],str2[];
while(cin >> str1 >> str2)
{
int len=strlen(str1);
int flag=;
int x=len;
for(int i=len-;i>=;i--)
{
if(str1[i]!='z')
{
flag=;
str1[i]++;
break;
}
else str1[i]='a';
}
if(flag==||strcmp(str2,str1)<=) cout << "No such string" << endl;
else cout << str1 << endl;
}
return ;
}
codeforces 518A. Vitaly and Strings的更多相关文章
- CodeForces 518A Vitaly and Strings (水题,字符串)
题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间. 析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行. 代 ...
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CF Vitaly and Strings
Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 482C Game with Strings(dp+概率)
题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...
- A. Vitaly and Strings
Vitaly is a diligent student who never missed a lesson in his five years of studying in the universi ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 682D Alyona and Strings (四维DP)
Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...
- Codeforces 149 E. Martian Strings
正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...
随机推荐
- Array类型(一)
1.创建数组的基本方式有两种,第一种使用Array构造函数 使用Array构造函数时可以省略new操作符 2.第二种方式是使用数组字面量表示法 由于IE的实现与其他浏览器不一致,因此我们不赞同使用这个 ...
- CentOS 6.4 下安装 Apache
下载地址:http://mirror.bit.edu.cn/ 参数 描述 prefix 安装目录 enable-rewrite 开启 rewrite 模块 sysconfdir 配置文件目录 ./co ...
- mysqldump 的方式来搭建master-->slave 的复制架构
1.master 上要满足的最小条件: 1.server_id 已经设置成了一个非0值 2.log_bin 配置好binlog 2.slave 上要满足的最小条件 1.server_id 已经设置成了 ...
- mysql中的意向锁IS,IX
知识储备: 1.官方文档上说mysql是支持非锁定读的:这个功能是这样实现的,如果事务a 要对行的数据进行更新的话,那么事务a要得到行的x锁,并把这一行 之前的样子记录在undo log里面,这样一 ...
- Discuz!X2.5论坛在IIS和Apache环境配置实现伪静态
最近在研究自己的网站,然后把这文章分享出来,让不清楚怎么设置的童鞋参考,高手可以飘过~~~ URL 静态化是一个有利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 ...
- linux下类似Bus Hound的工具
0推荐在linux大家有时候需要调试usb接口的串口消息,但是没有类似于windows下的bus hound工具,感觉比较痛苦,其实linux内核提供了usbmon这个工具,可以收集串口信息. 1.准 ...
- 51单片机实现对24C02进行页写、顺序读取并显示验证
//************************************************************************************* //**程序名称:51单 ...
- Qt中实现启动画面(延时过程中要加上app.processEvents())
纵所周之,当一个程序的启动比较耗时的时候,为了不让用户枯燥的等待或者是误以为程序运行异常了,所以我们都会在启动比较耗时的程序中加上启动界面 ,例如office软件等等. 在Qt中实现启动界面,主要就是 ...
- HttpApplication中的异步线程
一.Asp.net中的线程池设置 在Asp.net的服务处理中,每当服务器收到一个请求,HttpRuntime将从HttpApplication池中获取一个HttpApplication对象处理此请求 ...
- Android studio修改debug.keystore
在android studio项目中配置自定义的debug keystore 方法/步骤 在项目的build.gradle中添加如下内容: android { signingConfigs ...