题目大意:输入字符串,问该字符串是否为该字符串全排列按字典序排的最后一个,如果是,输出提示,不是则输出全排列的下一个字符串。
解题思路:用next_permutation函数,该函数用于求全排列的下一个,如果有返回值为1,没有则返回0。
ac代码:
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
char a[105];
while (scanf("%s", a)!=EOF && a[0]!='#')
if (next_permutation(a, a+strlen(a)))
printf("%s\n", a);
else
printf("No Successor\n");
return 0;
}