题目描述
输入10个学生的学号和5门课程的成绩,统计输出5门课总分最高和最低的学生的学号和他们的总分。
输入
每行6个整数,共10行。 其中,每行第一个整数表示学生的学号,剩下的5个数表示他5门课程的成绩。
输出
两行,每行两个整数。 其中第一行为总分最高的学生的学号,和他的总分,用空格隔开。 第二行为总分最低的学生的学号,和他的总分,用空格隔开。
样例输入
99211201 1 2 3 4 5
99211207 2 2 3 4 5
99211217 3 2 3 4 5
99211227 4 2 3 4 5
99211231 5 2 3 4 5
99211232 6 2 3 4 5
99211233 7 2 3 4 5
99211235 8 2 3 4 5
99211236 9 2 3 4 5
99211237 10 2 3 4 5
样例输出
99211237 24
99211201 15
AC代码
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct student
{
string id;//学号
int score;//分数
}stu[10];//只有十个学生
bool cmp(student stu1,student stu2)
{
//按照学生总分对结构体从大到小排序
return stu1.score > stu2.score;
}
int main()
{
int n;//n表示各科分数
for (int i = 0;i < 10;i++)
{
//输入学生的学号
cin >> stu[i].id;
for (int j = 0;j < 5;j++)
{
cin >> n;//5次循环,输入分数
stu[i].score += n;
}
}
//排序(从大到小)
sort(stu,stu + 10,cmp);
cout << stu[0].id << " " << stu[0].score << endl;//最大
cout << stu[9].id << " " << stu[9].score << endl;//最小
return 0;
}