cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

creating_strings.cpp (731B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 using ui = unsigned int;
      6 using l = long;
      7 using ul = unsigned long;
      8 using ll = long long;
      9 using ull = unsigned long long;
     10 
     11 using vi = vector<int>;
     12 using vui = vector<ui>;
     13 using vl = vector<l>;
     14 using vul = vector<ul>;
     15 using vll = vector<ll>;
     16 using vull = vector<ull>;
     17 
     18 set<string> res;
     19 
     20 void recurse(string cur, string src)
     21 {
     22 	if (src == "") {
     23 		res.insert(cur);
     24 		return;
     25 	}
     26 
     27 	for (int i = 0; i < src.length(); i++) {
     28 		string tmp = src;
     29 		tmp.erase(i, 1);
     30 		recurse(cur + src[i], tmp);
     31 	}
     32 }
     33 
     34 void solve()
     35 {
     36 	string l;
     37 	getline(cin, l);
     38 	sort(l.begin(), l.end());
     39 	recurse("", l);
     40 	cout << res.size() << "\n";
     41 	for (auto x : res) {
     42 		cout << x << "\n";
     43 	}
     44 }
     45 
     46 int main()
     47 {
     48 	solve();
     49 }