Search
 
SCRIPT & CODE EXAMPLE
 

CPP

nth permutation c++ stl

// C++ program to print nth permutation with
// using next_permute()
#include <bits/stdc++.h>
using namespace std;
  
// Function to print nth permutation
// using next_permute()
void nPermute(string str, long int n)
{
    // Sort the string in lexicographically
    // ascending order
    sort(str.begin(), str.end());
  
    // Keep iterating until
    // we reach nth position
    long int i = 1;
    do {
        // check for nth iteration
        if (i == n)
            break;
  
        i++;
    } while (next_permutation(str.begin(), str.end()));
  
    // print string after nth iteration
    cout << str;
}
  
// Driver code
int main()
{
    string str = "GEEKSFORGEEKS";
    long int n = 100;
    nPermute(str, n);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to use dec in C++ 
Cpp :: what are specialized classes c++ 
Cpp :: dev c++ tahe last word error 
Cpp :: map of vector of struct error 
Cpp :: C++ Fahrenheit to Celsius 
Cpp :: c++ writing to file 
Cpp :: screen record ios simulator 
Cpp :: replace character in a string c++ stack overflow 
Cpp :: input pdf latex 
Cpp :: How to block window resize sfml c++ 
Cpp :: c++ wait for user input 
Cpp :: c++ replace character in string 
Cpp :: max three values c++ 
Cpp :: ifstream relative file path 
Cpp :: delete specific vector element c++ 
Cpp :: qt label set text color 
Cpp :: how to declrae an array of size 1 
Cpp :: Write C++ program to copy one string to another string using pointers 
Cpp :: format c++ discord 
Cpp :: c++ show current time 
Cpp :: all of the stars lyrics 
Cpp :: c++ lcm 
Cpp :: how to add numbers in c++ 
Cpp :: count word accurances in a string c++ 
Cpp :: difference between lower and upper bound 
Cpp :: c++ replace string 
Cpp :: check if file is empty c++ 
Cpp :: int_max cpp 
Cpp :: nth node from end of linked list 
Cpp :: armstrong number in cpp 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =