blob: 689e0837a041dd0106f51343a0e29ef54e6a8216 (
plain)
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
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
void gen(std::map<char, int>& a, int count,
std::string start, std::vector<std::string>& res) {
if (count == 0)
res.push_back(start);
for (auto [k, v] : a) {
if (v > 0) {
a[k]--;
gen(a, count - 1, start + k, res);
a[k]++;
}
}
}
int main() {
std::string s;
std::map<char, int> a;
std::vector<std::string> sol;
std::cin >> s;
for (auto c : s)
a[c]++;
gen(a, s.size(), "", sol);
std::cout << sol.size() << "\n";
for (auto x : sol)
std::cout << x << "\n";
}
|