【思路】分别设置maxName,minName,maxNo,minNo,maxScore,minScore用于记录姓名,学号和成绩的最大,最小值方便最后进行输出。对输入的n组数据进行分数的比较,若大于最大值则姓名,学号最大值都设置为当前值,最小值也是如此。
满分的C++代码如下:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string name,maxName,minName;
string no,maxNo,minNo;
int score,maxScore,minScore;
cin >> n;
maxScore = 0;
minScore = 101;
for(int i=0;i<n;i++)
{
cin>>name>>no>>score;
if(score>maxScore)
{
maxScore = score;
maxName = name;
maxNo = no;
}
if(score<minScore)
{
minScore = score;
minName = name;
minNo = no;
}
}
cout << maxName << " " << maxNo << endl;
cout << minName << " " << minNo << endl;
return 0;
}