fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define sp << " " <<
  5.  
  6. struct student {
  7. string nm;
  8. int cls;
  9. char s;
  10. int id, math_marks, eng_marks, tot_marks;
  11. };
  12.  
  13. int main() {
  14. ios::sync_with_stdio(false);
  15. cin.tie();
  16.  
  17. int n; cin >> n;
  18. vector<student> v(n);
  19. for(auto &x : v) {
  20. cin >> x.nm >> x.cls >> x.s >> x.id >> x.math_marks >> x.eng_marks;
  21. x.tot_marks = x.eng_marks + x.math_marks;
  22. }
  23.  
  24. sort(v.begin(), v.end(), [](auto x, auto y) {
  25. if(x.tot_marks == y.tot_marks)
  26. return x.id < y.id;
  27. return x.tot_marks > y.tot_marks;
  28. });
  29.  
  30. for(auto x : v)
  31. cout << x.nm sp x.cls sp x.s sp x.id sp x.math_marks sp x.eng_marks sp "\n";
  32. }
Success #stdin #stdout 0s 5308KB
stdin
5
Munna 8 D 25 50 30
Shojoy 9 E 26 40 50
Asif 10 C 27 55 60
Joy 9 G 28 66 45
Bijoy 7 E 29 68 99
stdout
Bijoy 7 E 29 68 99 
Asif 10 C 27 55 60 
Joy 9 G 28 66 45 
Shojoy 9 E 26 40 50 
Munna 8 D 25 50 30