[CodeForces518A]Vitaly and Strings[字符串][构造]

来源:互联网 发布:哪件商品能在淘宝发布 编辑:程序博客网 时间:2024/06/17 04:08

题目链接:[CodeForces518A]Vitaly and Strings[字符串][构造]

题意分析:给出字符串s,t,问:是否有字符串,使得其大于s小于t。(s < t)

解题思路:题目即问:s的下一个排列是否小于t。

个人感受:下一个排列的构造我也是醉了。WA49都出来了XD

具体代码如下:

#include <iostream>#include <string>using namespace std;typedef long long ll;int main() {    string s1, s2, s3;    cin >> s1 >> s2;    int len = s1.size();    s3 = s1;    for (int i = len - 1; i >= 0; i--) //s1的下一个排列    {        if (s3[i] != 'z')        {            s3[i] += 1;            break;        }        else s3[i] = 'a';  //有点像26进制的意味,从末尾开始进位,超过z就进位直到不进位为止    }    if (s3 < s2)        cout << s3 << '\n';    else cout << "No such string\n";    return 0;}

0 0