-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreating_strings.cpp
More file actions
53 lines (37 loc) · 841 Bytes
/
Copy pathcreating_strings.cpp
File metadata and controls
53 lines (37 loc) · 841 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
#include <bits/stdc++.h>
using namespace std;
void create(string cur, int n, int freq[]) {
if (n == 0) {
cout << cur << endl;
}
for (int i = 0; i < 26; i++) {
if (freq[i] == 0) continue;
freq[i]--;
char k = 'a' + i;
create(cur + k, n - 1, freq);
freq[i]++;
}
}
int fact[9];
int main() {
string s;
cin >> s;
int freq[26];
memset(freq, 0, 26 * 4);
memset(fact, 1, 9 * 4);
int n = s.size();
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i <= 8; i++) {
fact[i] = (fact[i - 1] * i);
}
int tot = fact[n];
for (char i : s) freq[i - 'a']++;
for (int i = 0; i < 26; i++) {
tot = tot / fact[freq[i]];
}
cout << tot << endl;
string cur = "";
create(cur, n, freq);
return 0;
}