v 0. Pasted by slipstak2 as cpp at 2011-02-08 12:37:25 MSK and set expiration to never.

Paste will expire never.

  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int n;
  8. vector<int> p;
  9. vector<bool> used;
  10. string str;
  11. void lex(int pos)
  12. {
  13.     if (pos == n) {
  14.         for (int i=0;i<n;i++)
  15.             cout<<str[p[i]];
  16.         cout<<endl;
  17.         return;
  18.     }
  19.     for (int i=0;i<n;i++) {
  20.         if (!used[i]) {
  21.             used[i] = true;
  22.             p[pos] = i;
  23.  
  24.             lex(pos+1);
  25.            
  26.             p[pos] = 0; // debug only
  27.             used[i] = false;
  28.         }
  29.     }
  30. }
  31. int main()
  32. {
  33.     freopen("input.txt","r",stdin);
  34.     freopen("output.txt","w",stdout);
  35.  
  36.     cin>>str;
  37.     n = str.size();
  38.     p.resize(n);
  39.     used.resize(n);
  40.     lex(0);
  41.     return 0;
  42. }


Editing is locked.