Friday, December 8, 2017

UVa problem solution 146 - ID Codes

problem link:

Discuss: in this problem we just have to check is there any permutation next to given string. for it there is STL next_permutation() in cpp that will return zero if there no permutation after given string or return the next permutation of string. so we can easily use this STL.

try your self before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    while(cin >>str&&str!="#")
    {
        int  n,i,j,cnt=0,flag=0,mx=0;
       if(next_permutation(str.begin(),str.end()))
       {

        cout <<str<<endl;
       }
       else
        cout <<"No Successor"<<endl;

}
return 0;
}

No comments:

Post a Comment