ACdream 1056 Vitaly and Strings

一道水题,不过错了很多次,注意一下思维。

Description

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 stringss and t to Vitaly. The strings have the same length, they consist of lowercase English letters, strings is lexicographically smaller than stringt. Vitaly wondered if there is such string that is lexicographically larger than strings and at the same is lexicographically smaller than stringt. This string should also consist of lowercase English letters and have the length equal to the lengths of stringss and t.

Let's help Vitaly solve this easy problem!

Input

The first line contains strings (1 ≤ |s| ≤ 100), consisting of lowercase English letters. Here,|s| denotes the length of the string.

The second line contains stringt (|t| = |s|), consisting of lowercase English letters.

It is guaranteed that the lengths of stringss and t are the same and strings 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 Input

Input
a
c
Output
b
Input
aaa
zzz
Output
kkk
Input
abcdefg
abcdefh
Output
No such string


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

char s1[110], s2[110];
int main()
{
    int flag = 0;
    while(~scanf("%s%s", s1, s2)){
        int len = strlen(s1);
        for(int i = len-1; i >= 0; --i){
            if(s1[i] != 'z'){
                s1[i]++; flag = 1;
                break;
            }
            else
            s1[i] = 'a';
        }
        if(strcmp(s1, s2) >= 0 || flag == 0)
            printf("No such string\n");
        else
            printf("%s\n", s1);
    }
    return 0;
}

参考博客:http://www.cnblogs.com/I-love-HLD/p/4299364.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值