Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int o = 1;
- void print(string A, int size)
- {
- cout << o << ": ";
- cout << A;
- cout << endl;
- o++;
- }
- void swap(char& x, char& y, int& count)
- {
- int tmp = x;
- x = y;
- y = tmp;
- count++;
- }
- void next_perm(int k, string A, int size, int& count)
- {
- if (k == size)
- {
- print(A, size);
- return;
- }
- for (int i = k; i < size; i++)
- {
- swap(A[k], A[i], count);
- next_perm(k + 1, A, size,count);
- swap(A[k], A[i], count);
- }
- }
- int main()
- {
- int count = 0;
- string S;
- cin >> S;
- int N = S.length();
- cout << endl;
- next_perm(0, S, N, count);
- printf_s("num %d", count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement