#include #include #include #include

using namespace std;

struct Athlete { string name; float score1; float score2; float score3; };

bool compare(Athlete a, Athlete b) { float avg1 = (a.score1 + a.score2 + a.score3) / 3; float avg2 = (b.score1 + b.score2 + b.score3) / 3; return avg1 > avg2; }

int main() { int n, m; cin >> n >> m;

vector<Athlete> athletes;
for (int i = 0; i < n; i++) {
    Athlete athlete;
    cin >> athlete.name >> athlete.score1 >> athlete.score2 >> athlete.score3;
    athletes.push_back(athlete);
}

sort(athletes.begin(), athletes.end(), compare);

for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << athletes[i].name << " " << (athletes[i].score1 + athletes[i].score2 + athletes[i].score3) / 3 << endl;
}

return 0;
使用c++测试输入:3 4Alex 101 215 157Bolt 123 114 259Jack 809 128 205 Will 115 176 243预期输出:1 Jack 242 Alex 213 Bolt 184 Will 15

原文地址: https://www.cveoy.top/t/topic/hBB0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录