#include<bits/stdc++.h> #include<iostream> using namespace std; set<string> sem; void solve(string s, int i) { if (i == s.size()) { sem.insert(s); return; } for (int k = i; k < s.size(); k++) { swap(s[i], s[k]); solve(s, i + 1); swap(s[i], s[k]); } } int main() { string s = "hello"; solve(s, 0); cout << sem.size() << endl; for (auto it = sem.begin(); it != sem.end(); it++) { cout << *it << endl; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter