原题 如果出题人知道有Next_permutation这个函数,估计他就会放弃这个尽管有着这么丰富背景的题了。
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("146.txt","r",stdin);
#endif
char s[60];
while(scanf("%s",s)==1 &&s[0]!='#')
{
if(next_permutation(s,s+strlen(s)))
printf("%s\n",s);
else printf("No Successor\n");
}
return 0;
}