c++ program to find all lexicographical greatest permutations of string
// C++ program to print the lexicographically
// greater strings then the given string
#include <bits/stdc++.h>
using namespace std;
// Function to print the lexicographically
// greater strings then the given string
void print_lexiStrings(string S)
{
// Condition to check if there is no
// string which is lexicographically
// greater than string S
if (!next_permutation(S.begin(), S.end()))
cout << "-1";
// Move to the previous permutation
prev_permutation(S.begin(), S.end());
// Iterate over all the
// lexicographically greater strings
while (next_permutation(S.begin(), S.end())) {
cout << S << "\n";
}
}
// Driver Code
int main()
{
string S = "ABC";
print_lexiStrings(S);
}