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;
  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.  
  22.  
  23. sort(v.begin(), v.end(), [](auto x, auto y) {
  24. if(x.eng_marks == y.eng_marks && x.math_marks == y.eng_marks)
  25. return x.id < y.id;
  26. if(x.eng_marks == y.eng_marks)
  27. return x.math_marks > y.math_marks;
  28. return x.eng_marks > y.eng_marks;
  29. });
  30.  
  31. for(auto x : v)
  32. cout << x.nm sp x.cls sp x.s sp x.id sp x.math_marks sp x.eng_marks sp "\n";
  33. }
Success #stdin #stdout 0s 5312KB
stdin
6
akib 2 R 1001 32 53 
rakib 1 E 1002 94 88 
sakib 8 M 1003 34 88 
bokib 3 Q 1004 93 58 
jessica 4 F 1005 94 88 
noname 8 R 1006 17 61
stdout
rakib 1 E 1002 94 88 
jessica 4 F 1005 94 88 
sakib 8 M 1003 34 88 
noname 8 R 1006 17 61 
bokib 3 Q 1004 93 58 
akib 2 R 1001 32 53