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!
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.
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.
a
c
b
aaa
zzz
kkk
abcdefg
abcdefh
No such string
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.
大意是找一个序列长度和s,t的长度相同,并且字典序在s之后,在t之前。
看了数据之后发现有点小坑。
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<iomanip> 5 #include<cctype> 6 #include<string> 7 #include<cmath> 8 #include<cstdio> 9 #include<cstdlib> 10 #define LL long long 11 #define PF(x) ((x)*(x)) 12 #define LF(x) ((x)*PF(x)) 13 14 using namespace std; 15 const int INF=1<<31-1; 16 const int max9=1e9; 17 const int max6=1e6; 18 const int max3=1e3; 19 20 int gcd(int a,int b) 21 { 22 return b==0?a:gcd(b,a%b); 23 } 24 25 int main() 26 { 27 char str1[120],str2[120]; 28 while(cin >> str1 >> str2) 29 { 30 int len=strlen(str1); 31 int flag=0; 32 int x=len; 33 for(int i=len-1;i>=0;i--) 34 { 35 if(str1[i]!='z') 36 { 37 flag=1; 38 str1[i]++; 39 break; 40 } 41 else str1[i]='a'; 42 } 43 if(flag==0||strcmp(str2,str1)<=0) cout << "No such string" << endl; 44 else cout << str1 << endl; 45 } 46 return 0; 47 }