fork download
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. size_t imax = -1;
  7. vector< int > vec;
  8. int val = 0;
  9. while( cin >> val )
  10. {
  11. if( val )
  12. {
  13. vec.push_back(val);
  14. if( imax == -1 )
  15. imax = 0;
  16. else
  17. if( val > vec[imax] )
  18. imax= vec.size() - 1;
  19. }
  20. }
  21. if( imax != -1 )
  22. {
  23. cout<<"MAX_INDEX: "<<imax<<endl;
  24. cout<<"MAX VALUE: "<<vec[imax]<<endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 3464KB
stdin
5 6 -3 7 11 2 3 0
stdout
MAX_INDEX: 4
MAX VALUE: 11