Advertisement
Zennoma

perestanovochki

May 6th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int o = 1;
  4.  
  5. void print(string A, int size)
  6. {
  7. cout << o << ": ";
  8. cout << A;
  9. cout << endl;
  10. o++;
  11. }
  12. void swap(char& x, char& y, int& count)
  13. {
  14. int tmp = x;
  15. x = y;
  16. y = tmp;
  17. count++;
  18. }
  19. void next_perm(int k, string A, int size, int& count)
  20. {
  21. if (k == size)
  22. {
  23. print(A, size);
  24. return;
  25. }
  26. for (int i = k; i < size; i++)
  27. {
  28. swap(A[k], A[i], count);
  29. next_perm(k + 1, A, size,count);
  30. swap(A[k], A[i], count);
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. int count = 0;
  37. string S;
  38. cin >> S;
  39. int N = S.length();
  40. cout << endl;
  41. next_perm(0, S, N, count);
  42. printf_s("num %d", count);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement