fork download
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct student {
  7. char name[50];
  8. int roll;
  9. int marks;
  10. };
  11.  
  12. int main(){
  13. student s[5] = {{"Jonathan", 1, 99}, {"Mee", 2, 100}, {"Joe", 3, 50}, {"Blow", 4, 0}, {"Minhaj Shafqat", 5, 60}};
  14. const auto it = max_element(cbegin(s), cend(s), [](const auto& lhs, const auto& rhs){ return lhs.marks < rhs.marks; });
  15.  
  16. cout << it->roll << ' ' << it->name << ' ' << it->marks << " is top in the class\n";
  17. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
2 Mee 100 is top in the class