cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

creating_strings_1622.cpp (561B)


      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 }