fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int find_max(vector<int>a) {
  7. int max=0;
  8. for(int i=0;i<a.size();i++) if(a[i]>max) max=i;
  9. return max;
  10. }
  11.  
  12. int main() {
  13. vector<int> test; // Deklaration
  14. test.reserve(7); // Speicher-Reservierung
  15. test.push_back(10); // F
  16. test.push_back(45); // u
  17. test.push_back(12); // e
  18. test.push_back(23); // l
  19. test.push_back(39); // l
  20. test.push_back(63); // e
  21. test.push_back(33); // n
  22.  
  23. int idx_of_max = find_max(test); // Wird 5 sein, da das vorletzte Element
  24. // mit 63 den hoechsten Wert beinhaltet
  25. cout << idx_of_max;
  26. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
6