v 0. Pasted by slipstak2 as cpp at 2011-02-08 12:40:51 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 antylex(int pos) {
  12.     if (pos == -1) {
  13.         for (int i=0;i<n;i++)
  14.             cout<<str[p[i]];
  15.         cout<<endl;
  16.         return;
  17.     }
  18.     for (int i=n-1;i>=0;i--) {
  19.         if (!used[i]) {
  20.             used[i] = true;
  21.             p[pos] = i;
  22.  
  23.             antylex(pos-1);
  24.            
  25.             p[pos] = 0; // debug only
  26.             used[i] = false;
  27.         }
  28.     }
  29. }
  30. int main()
  31. {
  32.     freopen("input.txt","r",stdin);
  33.     freopen("output.txt","w",stdout);
  34.  
  35.     cin>>str;
  36.     n = str.size();
  37.     p.resize(n);
  38.     used.resize(n);
  39.     antylex(n-1);
  40.     return 0;
  41. }


Editing is locked.