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
  1. a
  2. c
output
  1. b
input
  1. aaa
  2. zzz
output
  1. kkk
input
  1. abcdefg
  2. abcdefh
output
  1. No such string
  1. 做了很长时间一直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'补齐并输出。
  1. #include<stdio.h>
  2. #include<string.h>
  3. char s1[200],s2[200],s[200];
  4. int main()
  5. {
  6. int n,m,i,j,len,flag,flag1,flag2,flag3;
  7. while(scanf("%s%s",s1,s2)!=EOF)
  8. {
  9. len=strlen(s1);
  10. flag=1;
  11. flag1=0;
  12. memset(s,0,sizeof(s));
  13. for(i=0;i<len;i++){
  14. if(i==len-1 && s2[i]-s1[i]<=1){
  15. flag=0;break;
  16. }
  17. else if(i==len-1 && s2[i]-s1[i]>=2){
  18. s[i]=s1[i]+1;break;
  19. }
  20. else if(s2[i]-s1[i]>=2){
  21. s[i]=s1[i]+1;
  22. for(j=i+1;j<len;j++){
  23. s[j]='z';
  24. }
  25. break;
  26. }
  27. else if(s2[i]-s1[i]==1){
  28. flag2=0;
  29. for(j=i+1;j<len;j++){
  30. if(s1[j]!='z'){
  31. flag2=1;break;
  32. }
  33. }
  34. if(flag2==1){
  35. s[i]=s1[i];
  36. for(j=i+1;j<len;j++){
  37. s[j]='z';
  38. }
  39. break;
  40. }
  41. else if(flag2==0){
  42.      flag3=0; 
  43.      for(j=i+1;j<len;j++){
  44.         if(s2[j]!='a'){
  45.       flag3=1;break;
  46.          }
  47.      }
  48.       if(flag3==0){
  49.         flag=0;break;
  50.        }
  51.        else{
  52.       s[i]=s2[i];
  53.       for(j=i+1;j<len;j++){
  54.       s[j]='a';
  55.      }
  56.                      break;
  57.       }
  58. }
  59. }
  60.  
  61. else if(s2[i]==s1[i]){
  62. s[i]=s1[i];continue;
  63. }
  64. else if(s1[i]>s2[i]){
  65. flag=0;break;
  66. }
  67.  
  68. }
  69. if(flag==1)printf("%s\n",s);
  70. else printf("No such string\n");
  71. }
  72. return 0;
  73. }

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. SQLI-LABS复现通关

    sql-lab 复现通关(深入学习) less-1 基于错误的单引号字符串 - 正常访问 127.0.0.1/?id=1 - 添加 ' 返回报错信息:You have an error in your ...

  2. idea 启动热部署Devtolls

    1.在子工程pom.xml中添加devtools jar包到需要启动的项目中 1 <dependency> 2 <groupId>org.springframework.boo ...

  3. Java 栈的使用

    讲栈之前,要先讲一下Deque双端队列 既可以添加到队尾,也可以添加到队首 既可以从队首获取又可以从队尾获取 public interface Deque<E> extends Queue ...

  4. 微信小程序 发送模板消息的功能实现

    背景 - 小程序开发的过程中,绝大多数会满足微信支付 - 那么,作为友好交互的体现,自然就会考虑到支付后的消息通知咯 - 所以,我的小程序项目也要求完成这个效果,so.分享一下自己的实现步骤,以方便道 ...

  5. ubuntu更新下载软件卡住0% [Connecting to archive.ubuntu.com (2001:67c:1360:8001::23)]

    一台ubuntu系统,查看硬件和配置环境的时候发现下载卡住了 根据提示就是有ipv6地址,系统也是配置了ipv6地址的.海外机器,而且可以ping通域名 最佳解决方案 我想出了如何让apt-get再次 ...

  6. 支持 gRPC 长链接,深度解读 Nacos 2.0 架构设计及新模型

    支持 gRPC 长链接,深度解读 Nacos 2.0 架构设计及新模型 原创 杨翊(席翁) 阿里巴巴云原生 2020-12-28    

  7. cookie中的domain和path

    div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...

  8. 从零开始学Java (五)条件选择

    if switch while do while for break continue 这块对于有语言基础的人来说可以跳过了. 注意有个equals方法. 1 public class Main { ...

  9. es5和es6的区别

    ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化ECMAScript6,即ES6,是ECMAScript的第六次修订,于2015年完成,也称ES2015ES ...

  10. 「NOIP2009」最优贸易

    「NOIP2009」最优贸易 「NOIP2009」最优贸易内存限制:128 MiB时间限制:1000 ms 题目描述C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意 ...