fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. void ShowVector(const std::vector<int> &v) {
  7. std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
  8. }
  9.  
  10. void ShowNewLine() { std::cout << std::endl; }
  11.  
  12. void ShowResults(const std::vector<int> &a, const std::vector<int> &b,
  13. const std::vector<int> &c) {
  14. std::cout << "results:" << std::endl;
  15. ShowVector(a);
  16. ShowNewLine();
  17. ShowVector(b);
  18. ShowNewLine();
  19. ShowVector(c);
  20. ShowNewLine();
  21. }
  22.  
  23. int main() {
  24. std::vector<int> a = {1, 2, 3, 4, 3, 2, 1};
  25. std::vector<int> b = {1, 1, 2, 2, 3, 3, 4};
  26. std::vector<int> c;
  27. c.resize(a.size());
  28. for (size_t i = 0; i < a.size(); i++) c[i] = std::max(a[i], b[i]);
  29. ShowResults(a, b, c);
  30. }
  31.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
results:
1 2 3 4 3 2 1 
1 1 2 2 3 3 4 
1 2 3 4 3 3 4