#include<iostream> #include<algorithm> using namespace std; int main(){ string s,s1; while(cin>>s&&s!="#"){ s1=s; next_permutation(s.begin(),s.end()); sort(s1.begin(),s1.end()); if(s==s1) cout<<"No Successor"<<endl; else cout<<s<<endl; } } |
Double click to view unformatted code.