aboutsummaryrefslogtreecommitdiff
path: root/01_introductory_problems/creating_strings_1622.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--01_introductory_problems/creating_strings_1622.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/01_introductory_problems/creating_strings_1622.cpp b/01_introductory_problems/creating_strings_1622.cpp
new file mode 100644
index 0000000..689e083
--- /dev/null
+++ b/01_introductory_problems/creating_strings_1622.cpp
@@ -0,0 +1,30 @@
1#include <iostream>
2#include <string>
3#include <map>
4#include <vector>
5
6void gen(std::map<char, int>& a, int count,
7 std::string start, std::vector<std::string>& res) {
8 if (count == 0)
9 res.push_back(start);
10 for (auto [k, v] : a) {
11 if (v > 0) {
12 a[k]--;
13 gen(a, count - 1, start + k, res);
14 a[k]++;
15 }
16 }
17}
18
19int main() {
20 std::string s;
21 std::map<char, int> a;
22 std::vector<std::string> sol;
23 std::cin >> s;
24 for (auto c : s)
25 a[c]++;
26 gen(a, s.size(), "", sol);
27 std::cout << sol.size() << "\n";
28 for (auto x : sol)
29 std::cout << x << "\n";
30}

Generated with cgit - Back to sebastiano.tronto.net