fork download
  1. #include <algorithm>
  2. #include <iterator>
  3. #include <iostream>
  4. #include <climits>
  5.  
  6. int main()
  7. {
  8. int maxv = std::numeric_limits<int>::min();
  9. int high_index;
  10. int curIndex = 1;
  11. std::for_each(std::istream_iterator<int>{std::cin},
  12. std::istream_iterator<int>{}, [&](int n)
  13. {
  14. if (maxv < n)
  15. {
  16. high_index = curIndex;
  17. maxv = n;
  18. }
  19. ++curIndex;
  20. });
  21. std::cout << "Highest index: " << high_index;
  22. }
  23.  
  24.  
Success #stdin #stdout 0s 4400KB
stdin
1 0 5 4 3
stdout
Highest index: 3