spider68

permutation

Mar 12th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void permute(string a, int l, int r)
  4. {
  5. if (l == r)
  6. cout<<a<<endl;
  7. else
  8. {
  9. for (int i = l; i <= r; i++)
  10. {
  11. swap(a[l], a[i]);
  12. permute(a, l+1, r);
  13. swap(a[l], a[i]);
  14. }
  15. }
  16. }
  17. int main()
  18. {
  19. string str = "ABC";
  20. int n = str.size();
  21. permute(str, 0, n-1);
  22. return 0;
  23. }
Add Comment
Please, Sign In to add comment