-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path195.cpp
More file actions
49 lines (47 loc) · 1016 Bytes
/
195.cpp
File metadata and controls
49 lines (47 loc) · 1016 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
#include <bits/stdc++.h>
using namespace std;
#define mem(x, y) memset(x, y, sizeof(x));
char a[100];
bool view[100];
int N;
vector<char> v;
bool comp(char b, char c) {
if (tolower(b) == tolower(c))
return b < c; // porer ta Capital hole swap kore age jabe
else
return tolower(b) < tolower(c); // eki thakbe
}
void call(int k) {
int i;
if (k == N) {
for (i = 0; i < N; i++) printf("%c", v[i]);
puts("");
return;
}
for (i = 0; i < N; i++) {
if (!view[i]) {
if (i == 0 || a[i] != a[i - 1] || view[i - 1]) {
view[i] = 1;
v.push_back(a[i]);
call(k + 1);
view[i] = 0;
v.pop_back();
}
}
}
return;
}
int main() {
int l, T;
scanf("%d", &T);
getchar();
while (T--) {
gets(a);
l = strlen(a);
N = l;
sort(a, a + l, comp);
mem(view, 0);
call(0);
}
return 0;
}