Paste will expire never.
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdio>
- using namespace std;
- int n;
- vector<int> p;
- vector<bool> used;
- string str;
- void lex(int pos)
- {
- if (pos == n) {
- for (int i=0;i<n;i++)
- cout<<str[p[i]];
- cout<<endl;
- return;
- }
- for (int i=0;i<n;i++) {
- if (!used[i]) {
- used[i] = true;
- p[pos] = i;
- lex(pos+1);
- p[pos] = 0; // debug only
- used[i] = false;
- }
- }
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- cin>>str;
- n = str.size();
- p.resize(n);
- used.resize(n);
- lex(0);
- return 0;
- }
Editing is locked.