-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCTDL007.cpp
More file actions
53 lines (50 loc) · 1.03 KB
/
SCTDL007.cpp
File metadata and controls
53 lines (50 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file SCTDL005.cpp
* @author long (you@domain.com)
* @brief C++ program to display all permutations
* of an array using STL in C++
* @version 0.1
* @date 2023-02-27
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> vt;
vector<int> permutation;
// Function to find the permutations
void findPermutations(int a[], int n)
{
do {
for(int i=0; i < n; i++)
{
permutation.push_back(a[i]);
}
vt.push_back(permutation);
permutation.clear();
} while (next_permutation(a, a + n));
}
int main()
{
int t;
cin >> t;
while(t--) {
int n, arr[10000];
cin >> n;
for(int i=0; i < n; i++)
{
arr[i] = i+1;
}
findPermutations(arr, n);
for(int i=vt.size()-1; i >= 0; i--)
{
for(int j=0; j < n; j++)
cout << vt[i][j];
cout << " ";
}
vt.clear();
cout << endl;
}
return 0;
}