Pages

Tuesday, June 5, 2012

146 - ID Codes


//
// main.cpp
// 146 - ID Codes
//
// Created by Panks on 31/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main (int argc, const char * argv[])
{
string input, next;
cin>>input;
while (input.compare("#")) {
next=input;
next_permutation(input.begin(), input.end());
if (!lexicographical_compare(input.begin(), input.end(), next.begin(), next.end())) {
if (input.compare(next)) {
cout<<input<<endl;
}
else{
cout<<"No Successor"<<endl;
}
}else{
cout<<"No Successor"<<endl;
}
cin>>input;
}
return 0;
}

No comments:

Post a Comment