Vitaly and Strings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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!

Input

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.

Output

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.

Sample test(s)
input
a
c
output
b
input
aaa
zzz
output
kkk
input
abcdefg
abcdefh
output
No such string
Note

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的更多相关文章

  1. codeforces 518A. Vitaly and Strings

    A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. 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 ...

  3. A. Vitaly and Strings

    Vitaly is a diligent student who never missed a lesson in his five years of studying in the universi ...

  4. CF Set of Strings

    Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. CF 543C Remembering Strings

    https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...

  6. CodeForces 518A Vitaly and Strings (水题,字符串)

    题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间. 析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行. 代 ...

  7. CF 149E Martian Strings 后缀自动机

    这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...

  8. CF 452E. Three strings(后缀数组+并查集)

    传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...

  9. cf 762C. Two strings

    因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...

随机推荐

  1. 执行原始的 SQL 查询

    The Entity Framework Code First API includes methods that enable you to pass SQL commands directly t ...

  2. Linux内存中的Cache真的能被回收么?

    在Linux系统中,我们经常用free命令来查看系统内存的使用状态.在一个RHEL6的系统上,free命令的显示内容大概是这样一个状态: [root@tencent64 ~]# free       ...

  3. PHP操作cookie函数:setcookie()与setrawcookie()

    PHP setcookie() 函数向客户端发送一个 HTTP cookie.cookie 是由服务器发送到浏览器的变量.cookie 通常是服务器嵌入到用户计算机中的小文本文件.每当计算机通过浏览器 ...

  4. Hibernate之继承映射

    1. Hibernate支持三种继承映射策略: –使用 subclass进行映射:将域模型中的每一个实体对象映射到一个独立的表中,也就是说不用在关系数据模型中考虑域模型中的继承关系和多态. –使用 j ...

  5. 教程-在F9后提示内存错误,点击了乎略,之后怎么取消乎略?

    问题现象:F9后,调试程序,提示内存错误,点击了“乎略”.之后再也没有出现错误了.可是想改这个BUG时,没法取消乎略了. 问题原因:在DLEPHI的选项中是这么一个地方是可以设置的. 问题处理:打开D ...

  6. JSF 2 multiple select dropdown box example

    In JSF, <h:selectManyMenu /> tag is used to render a multiple select dropdown box – HTML selec ...

  7. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  8. Javascript高级篇-面向对象的特性

    一.创建对象 1.1初始化器 var any={ name:"some", age:10, action:function(){ alert(this.name+":&q ...

  9. 第三方类AFNetworking

    1.AFNetworking简介 AFNetworking是一个在iOS开发中使用非常多的轻量级网络开源库适用于iOS以及Mac OS X.它构建于在(Apple iOS开发文档) NSURLConn ...

  10. Lua学习笔记(三):函数和闭包

    函数 lua的函数以function关键字开始,后跟函数名称和参数,最后以end结束,我们看一个简单的函数定义: function foo() --do something end function ...