Guest User

Untitled

a guest
Nov 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void Permute(string word, int times=0)
  7. {
  8. if(word.length() <= 1 or times == word.length())
  9. {
  10. cout << word << endl;
  11. }
  12. else
  13. {
  14. for(int i = 0; i < word.length(); i++)
  15. {
  16. if(i == word.length()-1)
  17. break;
  18. cout << word << endl;
  19. char letter = word[i];
  20. word[i] = word[i+1];
  21. word[i+1] = letter;
  22. }
  23. Permute(word, times+1);
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. string word;
  30. cout << "Digite uma palavra: ";
  31. cin >> word;
  32. Permute(word, 0);
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment