fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cassert>
  6.  
  7. using namespace std;
  8.  
  9. void input(int& m, int& p, int& q)
  10. {
  11. //ifstream fin("input.txt");
  12.  
  13. std::cin >> m >> p >> q;
  14.  
  15. //fin.close();
  16. }
  17.  
  18. void fillVec(vector <int>& elements, int m, int p, int q)
  19. {
  20. fill_n(elements.begin() + m, p, 1); // filling the vectors with correct amount of numbers. The 0's all already there, so I only put the 1's, and the 2's in.
  21. fill_n(elements.begin() + m + p, q, 2);
  22. }
  23.  
  24. void print(const vector<int>& nums, ostream& out)
  25. {
  26. for (int a : nums) { out << a << ' '; }
  27. out << endl;
  28. }
  29.  
  30. void permute(vector<int>& nums, ostream& out)
  31. {
  32. assert(std::is_sorted(nums.begin(), nums.end()));
  33. do {
  34. print(nums, out);
  35. } while (std::next_permutation(nums.begin(), nums.end()));
  36. }
  37.  
  38. int main()
  39. {
  40. int m, p, q;
  41.  
  42. input(m, p, q);
  43.  
  44. vector <int> elements(m + p + q);
  45. fillVec(elements, m, p, q);
  46.  
  47. //ofstream fout("output.txt");
  48.  
  49. permute(elements, std::cout);
  50.  
  51. //fout.close();
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5300KB
stdin
1 0 2
stdout
0 2 2 
2 0 2 
2 2 0