fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. int main()
  5. {
  6. const int xcnt = 6 , ycnt = 4;
  7.  
  8. // pattern
  9. int ary[xcnt] = {1,2,3,4,5,6};
  10. std::sort(ary, ary+xcnt);
  11.  
  12. // pick ycnt
  13. int ary_mask[xcnt] = {0};
  14. std::fill(ary_mask, ary_mask+ycnt, 1);
  15. std::sort(ary_mask, ary_mask+xcnt);
  16.  
  17. // do next_permutation for ary_mask
  18. int num = 0;
  19. do {
  20. // if ary_mask[i] == 1 , output ary[i]
  21. std::cout << std::setw(3) << ++num << " : " ;
  22. for(auto i = 0; i < xcnt; ++i)
  23. if(ary_mask[i])
  24. std::cout << ary[i] << ' ';
  25. std::cout << '\n';
  26. }while(std::next_permutation(ary_mask, ary_mask+xcnt));
  27. return 0;
  28. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
  1 : 3 4 5 6 
  2 : 2 4 5 6 
  3 : 2 3 5 6 
  4 : 2 3 4 6 
  5 : 2 3 4 5 
  6 : 1 4 5 6 
  7 : 1 3 5 6 
  8 : 1 3 4 6 
  9 : 1 3 4 5 
 10 : 1 2 5 6 
 11 : 1 2 4 6 
 12 : 1 2 4 5 
 13 : 1 2 3 6 
 14 : 1 2 3 5 
 15 : 1 2 3 4