成绩统计

· · 个人记录

#include <iostream>
#include <algorithm>
using namespace std;

struct Student {
  string name;
  int chn, math, total;

  bool operator < (Student oth) {
    return total < oth.total;
  }
};
Student s[1002];

int main() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i].name >> s[i].chn >> s[i].math;
    s[i].total = s[i].chn + s[i].math;
  }
  sort(s+1,s+n+1);
  for (int i = n; i >= 1; i--) {
    cout << s[i].name << ' ' << s[i].chn << ' ' << s[i].math << ' ' << s[i].total << '\n';
  }

  return 0;
}