题意:给你一个字符串,求它的下一个排列,按字典序。
思路:水题,用到一下next_permutation 求下一个排列函数。
//0 KB 18 ms
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define M 55
using namespace std;
int main ()
{
char str[M];
while (~scanf ("%s",str))
{
if (str[0] == '#')
break;
int len = strlen(str);
if (next_permutation(str,str+len))
printf ("%s\n",str);
else
printf ("No Successor\n");
}
return 0;
}