题目链接:点击打开链接
题意分析:给定两行长度相同的字符串s t ,求是否有以长度相同的字符串m使得字典序 s < m < t,若有输入任意一组答案即可。
将两行字符串看做两个数字s,t 即可,问题就转换为是否有一整数m满足s < m < t,不存在的情况只有t - s == 1 时。
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<string>
#include <algorithm>
using namespace std;
const int maxn = 105;
string s1,s2;
int main()
{
cin >> s1 >> s2;
int len = s1.length();
s1[len - 1]++;
int cnt = 0 ;
if(s1[len - 1] > 'z')//与整数加1进位一样
{
s1[len - 1] = 'a';
cnt = 1;
}
for(int i = len - 2; i >= 0; i--)
{
if(cnt == 1)
{
s1[i]++;
if(s1[i] > 'z')
{
s1[i] = 'a';
}
else cnt = 0;
}
}
if(s1 == s2) printf("No such string\n");
else cout << s1 << endl;
}