C++题目求解
1个回答
展开全部
#include <iostream>
#include <algorithm>
using namespace std;
struct transcript {
char name[11];
int Math, Chinese, English, Geography, sum;
} s[40];
bool cmp(transcript a, transcript b) {
return a.sum > b.sum;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> s[i].name >> s[i].Math >> s[i].Chinese >> s[i].English >> s[i].Geography;
s[i].sum = s[i].Math + s[i].Chinese + s[i].English + s[i].Geography;
}
sort(s, s + N, cmp);
for (int i = 0; i < 3; i++)
cout << s[i].name << endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询