題目描述:
讀入n名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。
輸入格式:每個測試輸入包含1個測試用例,格式爲
第1行:正整數n
第2行:第1個學生的姓名 學號 成績
第3行:第2個學生的姓名 學號 成績
... ... ...
第n+1行:第n個學生的姓名 學號 成績
其中姓名和學號均爲不超過10個字符的字符串,成績爲0到100之間的一個整數,這裏保證在一組測試用例中沒有兩個學生的成績是相同的。
輸出格式:對每個測試用例輸出2行,第1行是成績最高學生的姓名和學號,第2行是成績最低學生的姓名和學號,字符串間有1空格。
輸入樣例:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
輸出樣例:
Mike CS991301
Joe Math990112
C++代碼示例:
#include<iostream>
#include<string>
using namespace std;
struct StudentScore
{
string name;
string id;
int score;
};
int main()
{
int k,i,j,n,m,temp1,temp2,flag1,flag2;
cin>>k;
StudentScore stu[k];
temp1=0;temp2=101;
flag1=flag2=0;
for(i=0;i<k;i++)
{
cin>>stu[i].name>>stu[i].id>>stu[i].score;
if(temp1<=stu[i].score)
{
temp1=stu[i].score;
flag1=i;
}
if(temp2>=stu[i].score)
{
temp2=stu[i].score;
flag2=i;
}
}
cout<<stu[flag1].name<<" "<<stu[flag1].id<<endl;
cout<<stu[flag2].name<<" "<<stu[flag2].id<<endl;
return 0;
}