fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4.  
  5. void show_permutation(std::vector<unsigned int> v)
  6. {
  7. int i = 0;
  8. do {
  9. if (v.back() < v.front()) {
  10. continue;
  11. }
  12. std::cout << ++i << ". Permutation: ";
  13. copy(v.begin(), v.end(), std::ostream_iterator<unsigned int>(std::cout, " "));
  14. std::cout << std::endl;
  15. } while(std::next_permutation(v.begin(), v.end()));
  16. }
  17.  
  18. int main(int argc, char* argv[])
  19. {
  20. std::vector<unsigned int> v(4);
  21. std::iota(v.begin(), v.end(), 0);
  22.  
  23. show_permutation(v);
  24. }
  25.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1. Permutation: 0 1 2 3 
2. Permutation: 0 1 3 2 
3. Permutation: 0 2 1 3 
4. Permutation: 0 2 3 1 
5. Permutation: 0 3 1 2 
6. Permutation: 0 3 2 1 
7. Permutation: 1 0 2 3 
8. Permutation: 1 0 3 2 
9. Permutation: 1 2 0 3 
10. Permutation: 1 3 0 2 
11. Permutation: 2 0 1 3 
12. Permutation: 2 1 0 3