基本思路
- 姓名,name,学号,id,成绩,score,搞一个Student结构体,属性name、id和score
- 搞一个遍历,次数为n,查找属性score最小和最大的结构体,并输出相应的name和id
#include <bits/stdc++.h>
using namespace std;
struct Student{
string id;// 学号
string name;// 姓名
int score;// 成绩
}max_s, min_s;
int main(int argc, char *argv[]) {
int n, score;
string name, id;
cin >> n;
// init
max_s.score = -1;
min_s.score = 101;
for(int i = 0; i < n; i++){
cin >> name >> id >> score;
if(score > max_s.score){
max_s.name = name;
max_s.id = id;
max_s.score = score;
}
if(score < min_s.score){
min_s.name = name;
min_s.id = id;
min_s.score = score;
}
}
cout << max_s.name << ' ' << max_s.id << endl;
cout << min_s.name << ' ' << min_s.id << endl;
return 0;
}