Input andOutput
Input will consist of a series of lines each containing a stringrepresenting a code. The entire file will be terminated by a lineconsisting of a single #.Output will consist of one line for each code read containingthe successor code or the words `No Successor'.Sampleinputabaacb
cbbaa
#
Sampleoutputababac
No Successor
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main ()
{
char myints[100];
while(cin>>myints)
{
int len=strlen(myints);
int i,flag=0;
for(i=0;i<100;i++)
{
if(myints[i]<myints[i+1])
flag=1;
}
if(strcmp(myints,"#")==0) break;
else if(flag==0)
cout<<"No Successor\n";
else
{
next_permutation(myints,myints+len);
cout <<myints<<endl;
}
}
return 0;
}
Input will consist of a series of lines each containing a stringrepresenting a code. The entire file will be terminated by a lineconsisting of a single #.Output will consist of one line for each code read containingthe successor code or the words `No Successor'.Sampleinputabaacb
cbbaa
#
Sampleoutputababac
No Successor
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main ()
{
char myints[100];
while(cin>>myints)
{
int len=strlen(myints);
int i,flag=0;
for(i=0;i<100;i++)
{
if(myints[i]<myints[i+1])
flag=1;
}
if(strcmp(myints,"#")==0) break;
else if(flag==0)
cout<<"No Successor\n";
else
{
next_permutation(myints,myints+len);
cout <<myints<<endl;
}
}
return 0;
}