fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. std::pair<int, int> Find2Max(std::vector<int> a)
  6. {
  7. std::sort(a.begin(), a.end());
  8.  
  9. return std::make_pair(*(a.end()-1), *(a.end()-2));
  10. }
  11.  
  12. int main ()
  13. {
  14. std::vector<int> v = { 100, 20, 3, 4, 50, 6, 70, 8, 90, 10 };
  15.  
  16. auto f2mRes = Find2Max(v);
  17. std::cout << f2mRes.first << ' ' << f2mRes.second << std::endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
100 90