from itertools import permutations
from itertools import combinations
p = permutations([1,2,4]) # or permutations([1, 2, 3], 2)
for i in p:
print(i)
c = combinations([1,2,3],2)
for j in c:
print(j)
// C++ program to print all
// permutations with duplicates allowed
#include <bits/stdc++.h>
using namespace std;
// Function to print permutations of string
// This function takes three parameters:
// 1. String
// 2. Starting index of the string
// 3. Ending index of the string.
void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
swap(a[l], a[i]);
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}
// Driver Code
int main()
{
string str = "ABC";
int n = str.size();
permute(str, 0, n-1);
return 0;
}
Code Example |
---|
Cpp :: c++ negate boolean |
Cpp :: Check if two stacks are the same using C++ |
Cpp :: c++ power operator |
Cpp :: is vowel c++/c |
Cpp :: e.cpp |
Cpp :: return value optimization example |
Cpp :: c++ Is there still a need to provide default constructors to use STL containers |
Cpp :: prime template c++ |
Cpp :: Overloading IO Stream |
Cpp :: executing linux scripts |
Cpp :: online compiler cpp |
Cpp :: c++ projects |
Cpp :: c++ if else if |
Cpp :: fenwick tree |
Cpp :: program to find third smallest number c++ |
Cpp :: are arrays faster than vectors c++ |
Cpp :: c++ inline if |
Cpp :: c++ error 0xC0000005 |
Cpp :: friend class c++ |
C :: clear screen c |
C :: allow unrelated histories |
C :: bash check if inside lxc |
C :: rl_replace_line |
C :: prime numbers c |
C :: find the largest number among five numbers in c language |
C :: c round function |
C :: how to print the first character of a string in c |
C :: c programing strtok use |
C :: c modify char array |
C :: add a item to cart woocomerce with quantity |