I was trying to find the Maximum average marks of student in 2D vector of string. After compilation i am getting Runtime error.
For Eg . The Average Marks of students are : James 80 , Nick 65 , Amit 50 , Fernando 40. Now the maximum Average among them are James 80
Is there any issue inside Lambda function ? Why is the below program Crashing?
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<string> > vect{{"James", "70"}, {"Fernando", "40"},
{"Nick", "60"}, {"James", "90"},
{"Nick", "70"}, {"Amit", "50"}};
auto it = max_element(vect.cbegin(), vect.cend(),
[](auto const& left, auto const& right) {
return stoi(left[1]) < stoi(left[2]);
});
cout << (*it)[0] << " : " << (*it)[1] << endl;
return 0;
}
Expected output : James 80