Advertisement
yuawn

10HW1

Oct 3rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. using namespace std;
  4.  
  5. map<char , bool> mp;
  6. vector<char> p;
  7. string s;
  8.  
  9. void print(){
  10.     for( auto z : p ) putchar( z );
  11.     puts("");
  12. }
  13.  
  14. void DFS( int l ){
  15.     if( l == s.size() - 1 ){
  16.         print();
  17.         return;
  18.     }
  19.     for( auto z : s ){
  20.         if( mp[ z ] ) continue;
  21.         p.pb( z );
  22.         mp[ z ] = 1;
  23.         DFS( l + 1 );
  24.         mp[ z ] = 0;
  25.         p.pop_back();
  26.     }
  27.     return;
  28. }
  29.  
  30. int main(){
  31.     cin >> s;
  32.     for( auto z : s ){
  33.         p.pb( z );
  34.         mp[ z ] = 1;
  35.         DFS( 0 );
  36.         mp[ z ] = 0;
  37.         p.pop_back();
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement