poj 1146 ID Codes
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string line;
while(cin>>line&&line!="#")
{
if(next_permutation(line.begin(),line.end()))
cout<<line<<endl;
else
cout<<"No Successor\n";
}
return 0;
}