Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. 4 3 2 1 5
  2. 4 3 5 1 2
  3. 2 3 4 1 5
  4. 2 3 5 1 4
  5. 5 3 2 1 4
  6. 5 3 4 1 2
  7.  
  8. int perm[3] = {2, 4, 5};
  9. const int N = sizeof(perm) / sizeof(int);
  10.  
  11. std::map<int,int> fixed; // note: zero-indexed
  12. fixed[1] = 3;
  13. fixed[3] = 1;
  14.  
  15. do {
  16. for (int i=0, j=0; i<5; i++)
  17. if (fixed.find(i) != fixed.end())
  18. std::cout << " " << fixed[i];
  19. else
  20. std::cout << " " << perm[j++];
  21. std::cout << std::endl;
  22. } while (std::next_permutation(perm, perm + N));
  23.  
  24. 2 3 4 1 5
  25. 2 3 5 1 4
  26. 4 3 2 1 5
  27. 4 3 5 1 2
  28. 5 3 2 1 4
  29. 5 3 4 1 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement