C++编程题,感谢感谢感谢!!!
1个回答
展开全部
#include <iostream>
#include <algorithm>
using namespace std;
struct Student {
int id;
string name;
int score;
} s[5];
bool comp(const Student &a, const Student &b) {
return a.score > b.score;
}
int temp;
int main() {
for(int i = 0; i < 5; ++i) {
cin >> s[i].id;
cin >> s[i].name;
cin >> temp; s[i].score += temp;
cin >> temp; s[i].score += temp;
cin >> temp; s[i].score += temp;
}
sort(s, s + 5, comp);
cout << s[4].id << ' '
<< s[4].name << ' '
<< s[4].score << endl;
cout << s[0].id << ' '
<< s[0].name << ' '
<< s[0].score << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询