本题思路非常简单,其实根本不需要使用结构体,也不需要排序,一边输入一遍比较大小即可,下面的代码其实较为繁琐。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct stu_node
{
string stu_name;
string stu_num;
int fneshu;
};
int main(int argc, char** argv) {
int student_num;
int i;
int max,min,max_index=0,min_index=0;
cin>>student_num;
if(student_num<1)
return 0;
stu_node node[student_num];
for(i=0;i<student_num;i++)
{
cin>>node[i].stu_name >>node[i].stu_num >>node[i].fneshu;
}
//sort();
max = node[0].fneshu;
min = node[0].fneshu;
for(i=0;i<student_num;i++)
{
if(node[i].fneshu>max)
{
max =node[i].fneshu;
max_index = i;
}
if(node[i].fneshu<min)
{
min =node[i].fneshu;
min_index = i;
}
}
cout <<node[max_index].stu_name << " " << node[max_index].stu_num << endl;
cout <<node[min_index].stu_name << " " << node[min_index].stu_num << endl;
return 0;
}