fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. void ShowAllPermutationsFromFirst(std::string first_permutation_string) {
  5. do {
  6. std::cout << first_permutation_string << '\n';
  7. }
  8. while (std::next_permutation(first_permutation_string.begin(),
  9. first_permutation_string.end()));
  10. }
  11.  
  12. std::string CreateFirstPermutation(size_t number_of_zeros,
  13. size_t number_of_ones) {
  14. std::string zeros_string(number_of_zeros, '0');
  15. std::string ones_string(number_of_ones, '1');
  16. return zeros_string + ones_string;
  17. }
  18.  
  19. void ShowPermutations(size_t number_of_zeros, size_t number_of_ones) {
  20. ShowAllPermutationsFromFirst(
  21. CreateFirstPermutation(number_of_zeros, number_of_ones));
  22. }
  23.  
  24. int main() {
  25. ShowPermutations(5, 3);
  26. return 0;
  27. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
00000111
00001011
00001101
00001110
00010011
00010101
00010110
00011001
00011010
00011100
00100011
00100101
00100110
00101001
00101010
00101100
00110001
00110010
00110100
00111000
01000011
01000101
01000110
01001001
01001010
01001100
01010001
01010010
01010100
01011000
01100001
01100010
01100100
01101000
01110000
10000011
10000101
10000110
10001001
10001010
10001100
10010001
10010010
10010100
10011000
10100001
10100010
10100100
10101000
10110000
11000001
11000010
11000100
11001000
11010000
11100000