生成下一个排列, 用 next_permutation 。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { char s[60]; int i, n; while(scanf("%s",s)) { if(s[0]=='#')break; n = strlen(s); if( next_permutation(s,s+n) ) printf("%s\n",s); else printf("No Successor\n"); } return 0; }