CF 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.
思路:将字符串看成数字,先从左向右找到第一个不相同的,然后把最右边那位加一,如果超出了Z就进位。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; int main(void)
{
string s;
string t;
int loc,len,flag; cin >> s >> t;
if(s == t)
puts("No such string");
else
{
len = s.size();
flag = ; for(int i = ;i < len;i ++)
if(s[i] < t[i])
{
loc = i;
break;
}
if(s[loc] + < t[loc])
{
s[loc] += ;
flag = ;
}
else
{
int box = ;
int add = ;
for(int i = len - ;i > loc;i --)
{
flag = ;
s[i] += box + add;
if(s[i] > 'z')
{
s[i] = 'a';
add = ;
box = ;
}
else
{
add = ;
box = ;
}
}
s[loc] += add;
if(s == t)
{
puts("No such string");
return ;
}
}
if(flag)
cout << s << endl;
else
puts("No such string");
} return ;
}
CF Vitaly and Strings的更多相关文章
- codeforces 518A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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 ...
- A. Vitaly and Strings
Vitaly is a diligent student who never missed a lesson in his five years of studying in the universi ...
- CF Set of Strings
Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 543C Remembering Strings
https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...
- CodeForces 518A Vitaly and Strings (水题,字符串)
题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间. 析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行. 代 ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- CF 452E. Three strings(后缀数组+并查集)
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...
- cf 762C. Two strings
因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...
随机推荐
- c函数调用过程原理及函数栈帧分析
转载自地址:http://blog.csdn.net/zsy2020314/article/details/9429707 今天突然想分析一下函数在相互调用过程中栈帧的变化,还是想尽量以比 ...
- rsync 无密码传输文件
最近机器迁移,需要备份文件,但各个机器间不能穿梭,即无法通过scp来传输文件, 在运维的建议下,选用了rsync作为传输的工具. 默认情况Ubuntu安装了rsync服务,但在/etc下没有配置文件, ...
- [iOS基础控件 - 6.11.4] storyboard 的 Segue
A.概念 storyboard中的跳转事件连线,都是一个UIStoryboardSegue对象(Segue) 来源控制器 触发控制器 目标控制器 跳转到的控制器 Seg ...
- 关闭Linux里边的selinux
首先我们可以用命令来查看selinux的状态 getenforce 这个命令可以查看到selinux的状态,当前可以看到是关闭状态的. 还有一个命令也可以查看出selinux的状态. sest ...
- ASP.NET WebForm中前台代码如何绑定后台变量
转载自 http://www.cnblogs.com/lerit/archive/2010/10/22/1858007.html 经常会碰到在前台代码中要使用(或绑定)后台代码中变量值的问题.一般有& ...
- ASP.Net自定义重写Http Server标头
Net中我们为了安全或其他原因起见 可能需要修改我们的标头报文等 以下方法我们通过使用HTTP Module来使用编程的方式来去除或修改它 首先我们自定义一个类CustomServerHeaderMo ...
- MDF文件数据恢复
- 配置 dovecat 的 log
关于 dovecot 的日志配置,请检查 conf.d/10-logging.conf 文件, 特别需要提示的是将 错误/信息 文件分开保存,建议分别设置 log_path / info_log_pa ...
- UVa10050 Hartals
// 题意:输入n和p个整数H[i],其中H[i]表示每H[i]天会有一次活动(但周五周六除外).输出前n天中有多少天有活动.模拟从周日开始. #include<cstdio> #in ...
- vector 与map的下标操作
1.vector的下标操作不会添加元素,只能针对已经存在的元素操作. 2.map的下标操作具有副作用,key不存在,会在map中添加一个具有该key的新元素,新元素的value使用默认构造方法. 3. ...