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
做了很长时间一直WA,主要是考虑不充分。先考虑末尾的情况,然后如果前面对应第i个字符中第二串比第一串大于等于2就可以直接使得s[i]=s1[i]+1,然后其他的用'z'补齐,如果前面对应第i个字符中第二串比第一串大1就要分两种情况讨论,第一种是看s1中剩下字符是不是都为'z',只要一个不是,s[i]=s1[i],i后面的都用'z'补齐并输出。如果这种情况不满足,那么就看s2中是不是所有的字符都是'a',如果有一个不是,s[i]=s2[i],i后面的都用'a'补齐并输出。
#include<stdio.h>
#include<string.h>
char s1[200],s2[200],s[200];
int main()
{
int n,m,i,j,len,flag,flag1,flag2,flag3;
while(scanf("%s%s",s1,s2)!=EOF)
{
len=strlen(s1);
flag=1;
flag1=0;
memset(s,0,sizeof(s));
for(i=0;i<len;i++){
if(i==len-1 && s2[i]-s1[i]<=1){
flag=0;break;
}
else if(i==len-1 && s2[i]-s1[i]>=2){
s[i]=s1[i]+1;break;
}
else if(s2[i]-s1[i]>=2){
s[i]=s1[i]+1;
for(j=i+1;j<len;j++){
s[j]='z';
}
break;
}
else if(s2[i]-s1[i]==1){
flag2=0;
for(j=i+1;j<len;j++){
if(s1[j]!='z'){
flag2=1;break;
}
}
if(flag2==1){
s[i]=s1[i];
for(j=i+1;j<len;j++){
s[j]='z';
}
break;
}
else if(flag2==0){
     flag3=0; 
     for(j=i+1;j<len;j++){
        if(s2[j]!='a'){
      flag3=1;break;
         }
     }
      if(flag3==0){
        flag=0;break;
       }
       else{
      s[i]=s2[i];
      for(j=i+1;j<len;j++){
      s[j]='a';
     }
                     break;
      }
}
} else if(s2[i]==s1[i]){
s[i]=s1[i];continue;
}
else if(s1[i]>s2[i]){
flag=0;break;
} }
if(flag==1)printf("%s\n",s);
else printf("No such string\n");
}
return 0;
}

A. Vitaly and Strings的更多相关文章

  1. CF Vitaly and Strings

    Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. codeforces 518A. Vitaly and Strings

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

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

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

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

  5. Codeforces Round #293 (Div. 2)

    A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...

  6. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  7. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  8. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

随机推荐

  1. Invalid bound statement (not found): com.xxx.xxx.dao.ShopMapper.insertShop

    mybatis在编写完SQL,进行测试的时候出现了错误,显示 org.apache.ibatis.binding.BindingException: Invalid bound statement ( ...

  2. 跟我一起学Redis之加个哨兵让主从复制更加高可用

    前言 主从复制的实现在上一篇已经分享过,虽然主从复制本身的确让读写分离更加高效,但是对于整体高可用存在很大的劣势:当主节点宕机了之后还需要人为重新进行主从关系配置:这不是开玩笑嘛,这样人为干预,故障恢 ...

  3. 简要MR与Spark在Shuffle区别

    一.区别 ①本质上相同,都是把Map端数据分类处理后交由Reduce的过程. ②数据流有所区别,MR按map, spill, merge, shuffle, sort, r educe等各阶段逐一实现 ...

  4. 基于numpy.einsum的张量网络计算

    张量与张量网络 张量(Tensor)可以理解为广义的矩阵,其主要特点在于将数字化的矩阵用图形化的方式来表示,这就使得我们可以将一个大型的矩阵运算抽象化成一个具有良好性质的张量图.由一个个张量所共同构成 ...

  5. USB限流芯片,4.8A最大,过压关闭6V

    PW1503,PW1502是超低RDS(ON)开关,具有可编程的电流限制,以保护电源源于过电流和短路保护.它具有超温保护以及反向闭锁功能. PW1503,PW1502采用薄型(1毫米)5针薄型SOT2 ...

  6. Apache Unomi 远程代码执行漏洞复现(CVE-2020-13942)

    一.漏洞描述 Apache Unomi 是一个基于标准的客户数据平台(CDP,Customer Data Platform),用于管理在线客户和访客等信息,以提供符合访客隐私规则的个性化体验.在Apa ...

  7. 接口新建学习---cookie策略

    一.为什么要添加cookie? 模拟浏览器,因为http是无状态协议,像览器一样的存储和发送Cookie,如果发送一个http请求他的响应中包含Cookie,那么Cookie Manager就会自动地 ...

  8. 有状态 无状态 stateful stateless monolithic architecture microservice architecture 单体架构

    为什么游戏公司的server不愿意微服务化? - 知乎 https://www.zhihu.com/question/359630395 我大概说了,方便测试,方便维护,方便升级,服务之间松耦合,可多 ...

  9. (Sql Server)SQL FOR XML

    摘要:sql中的for xml语法为表转化为xml提供了很好的支持,当然使用同样的程序语言也能够达到同样的效果,但是有了for xml将使得这一切更加的方便. 主要内容: Select 的查询结果会作 ...

  10. Coded UI

    Coded UI Test是Visual Studio 2010对于Testing Project(测试工程)提供的关于UI自动化测试的框架,支持Win32,Web,WPF等UI的自动化测试,是一个非 ...