-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path1023-Discovering-Perumutations.cpp
More file actions
85 lines (57 loc) · 925 Bytes
/
Copy path1023-Discovering-Perumutations.cpp
File metadata and controls
85 lines (57 loc) · 925 Bytes
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define rint(x) scanf("%d", &x)
using namespace std;
int fact(int x)
{
int ans = 1;
while(x) {
ans = ans * x;
x--;
}
return ans;
}
int main()
{
char c;
int t;
int k;
int n;
int tot;
rint(t);
for (int p = 1; p <= t; p++) {
c = 'A';
string a;
rint(n);
rint(k);
for (int i = 0; i < n; i++) {
a = a + c;
c = c + 1;
}
printf("Case %d:\n", p);
if(n < 5) {
tot = fact(n);
if(k < tot) {
for (int i = 0; i < k; i++) {
cout << a << endl;
next_permutation(a.begin(), a.end());
}
}
else {
if(k >= tot) {
for (int i = 0; i < tot; i++) {
cout << a << endl;
next_permutation(a.begin(), a.end());
}
}
}
}
else {
for (int i = 0; i < k; i++) {
cout << a << endl;
next_permutation(a.begin(), a.end());
}
}
}
}