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;
}

最新文章

  1. IOS第18天(1,核心动画layer, 旋转,缩放,平移,边框,剪裁,圆角)
  2. 批处理中的echo命令图文详解
  3. 使用命令参数方式指定log4j配置文件
  4. Cent OS yum 安装 Adobe flash player
  5. tostring格式化输出
  6. javaweb学习总结十一(JAXP对XML文档进行DOM解析)
  7. C++STL学习笔记_(4)queue
  8. 对CLR异常和状态管理的一点理解
  9. php转义和去掉html、php标签函数
  10. 用script实现内容显示,并使用json传输数据
  11. CSS 去除浏览器默认 轮廓外框
  12. HDU_2027——统计元音
  13. iOS socket 实现tcp和服务器长链接的简单使用心得
  14. 安装、配置、启动FTP、SSH或NFS服务
  15. Spring中一个类的注入和引用是不一样的
  16. 使用Spring Boot快速构建基于SQLite数据源的应用
  17. 自动化测试-Selenium家谱介绍
  18. PLSQL 注册码
  19. markdown小知识总结
  20. python 解析命令行

热门文章

  1. 第一章计算机网络概述---OSI七层网络模型
  2. 【Linux】ethtool 用法
  3. 【Oracle】oracle pctfree和pctused详解
  4. [Usaco2009 Feb]Bullcow 牡牛和牝牛
  5. 【高并发】ReadWriteLock怎么和缓存扯上关系了?!
  6. js中常用追加元素的几种方法
  7. Vue使用Ref跨层级获取组件实例
  8. Devexpress DockManager多页面浮动窗口会关闭所有页面的问题
  9. Angular入门到精通系列教程(14)- Angular 编译打包 &amp; Docker发布
  10. Python_ 1生成器(上)初识生成器