diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /01_introductory_problems/creating_strings_1622.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '')
| -rw-r--r-- | 01_introductory_problems/creating_strings_1622.cpp | 30 |
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 | |||
| 6 | void 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 | |||
| 19 | int 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 | } | ||
