思路:
此题是比较简单的一个模拟题,两个struct类型的变量分别记录第一名和最后一名,另一个变量输入,每次输入就判断并更新第一名和最后一名的信息。
代码:
#include<iostream>
#include<string>
using namespace std;
struct Student
{
string name;
string id;
int score;
};
int main()
{
struct Student s, first, last;
int n;
first.score = -1;
last.score = 101;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s.name >> s.id >> s.score;
if (s.score>first.score)
first = s;
if (s.score < last.score)
last = s;
}
cout << first.name << " " << first.id << "\n";
cout << last.name << " " << last.id;
//while (1)
//{
//}
return 0;
}