PAT乙级1004
1004 成绩排名 (20 分)
读入 n(>0)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。
#include<iostream>
#include<string.h>
using namespace std;
class student{
public:
void set(char a[],char b[],int c)
{
strcpy(name,a);
strcpy(num,b);
score=c;
}
int sc()
{
return score;
}
void prin()
{
cout<<name<<" "<<num<<endl;
}
private:
char name[10];
char num[10];
int score;
};
int main()
{
int n;
cin>>n;
cin.get();
student temp[101];
int i=0;
for(i=0;i<n;i++)
{
char a[10];
char b[10];
int c;
cin>>a>>b>>c;
temp[i].set(a,b,c);
}
for(i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(temp[j].sc()<temp[j+1].sc())
{
student a;
a=temp[j];
temp[j]=temp[j+1];
temp[j+1]=a;
}
}
}
temp[0].prin();
temp[n-1].prin();
return 0;
}