Advertisement
NickAndNick

Перестановки символов в строке

Jul 4th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void recursive_permutation(string, string);
  6. void permutations_of_string(string);
  7.  
  8. int main() {
  9.     cout << " Password: ";
  10.     string password;
  11.     cin >> password;
  12.     permutations_of_string(password);
  13.     cin.sync();
  14.     cin.get();
  15.     return 0;
  16. }
  17.  
  18. void recursive_permutation(string _so_far, string _rest) {
  19.     if (_rest == "") cout << _so_far << endl;
  20.     else {
  21.         string next, save;
  22.         for (size_t i = 0; i < _rest.size(); i++) {
  23.             next = _so_far + _rest[i];
  24.             save = _rest.substr(0, i) + _rest.substr(i + 1);
  25.             recursive_permutation(next, save);
  26.         }
  27.     }
  28. }
  29.  
  30. void permutations_of_string(string _str) {
  31.     recursive_permutation("", _str);    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement