讀入 n(>0)名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。
輸入格式:
每個測試輸入包含 1 個測試用例,格式爲
第 1 行:正整數 n
第 2 行:第 1 個學生的姓名 學號 成績
第 3 行:第 2 個學生的姓名 學號 成績
... ... ...
第 n+1 行:第 n 個學生的姓名 學號 成績
其中姓名和學號均爲不超過 10 個字符的字符串,成績爲 0 到 100 之間的一個整數,這裏保證在一組測試用例中沒有兩個學生的成績是相同的。
輸出格式:
對每個測試用例輸出 2 行,第 1 行是成績最高學生的姓名和學號,第 2 行是成績最低學生的姓名和學號,字符串間有 1 空格。
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
struct student
{
string name,number;
int score;
};
int main()
{
int n,maxscore,minscore,min1=101,max1=-1;
student s[1000];
cin >> n;
for(int i=0; i<n; i++)
{
cin >> s[i].name >> s[i].number >> s[i].score;
if(max1<s[i].score)
{
max1 = s[i].score;
maxscore = i;
}
if(min1>s[i].score)
{
min1 = s[i].score;
minscore = i;
}
}
cout << s[maxscore].name << " " << s[maxscore].number <<endl;
cout << s[minscore].name << " " <<s[minscore].number<<endl;
system("pause");
return 0;
}