1.输入 n 个学生的信息,每个学生信息包括姓名、身高、学号。编程输出身高最高的学生的信息。
输入:
5
John 172 20160302
David 173 20160306
Jason 168 20160309
Jack 152 20160311
Kitty 147 20160319
输出:
David 173 20160306
万能头文件:
#include<bits/stdc++.h>
using namespace std;
结构体定义:
struct student
{
string name;//学生姓名
int cz;//身高
string b;//学号
} a[105];
自定义函数排序:
bool cmp(student a,student b)
{
return a.cz>b.cz;
}
输入且排序:
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].cz>>a[i].b;
}
sort(a+1,a+1+n,cmp);
输出:
cout<<a[1].name<<" "<<a[1].cz<<" "<<a[1].b<<" ";