梦山高中现需要将某普通班的最优秀学生调整入理科实验班。为此,将从两个方面考察学生,一是数学和英语两门课的总分;另一个是所有四门课的总分。分别找出两科总分和全科总分的第一名,并从中决定调整人选。
输入将首先输入学生数n, (n为不超过80的正整数);接下来依次输入各位学生的学号,数学、英语、语文、理科综合成绩。学号及四科成绩均为不超过300的正整数。
输出时:第一行输出两科总分第一的学号,第二行输出四科总分第一的学号。 约定在两位学生成绩相同时,优先选择学号较小的学生;各位学生的学号均不相同。
裁判测试程序样例:
输入样例:
3
6 148 150 120 252
5 148 150 117 260
7 145 148 128 287
输出样例:
5
7
经过参考资料 自己整理下答案 欢迎大佬批评指正
bool s2(const Student &a, const Student &b) //a b 为哪个学生 a学生 b学生 比较 a b 数学和英语成绩 b大则返回true
{
if(a.score[0]+a.score[1]>b.score[0]+b.score[1])
{
return true;
}
else if((a.score[0]+a.score[1]==b.score[0]+b.score[1])&&(a.num<b.num))
{
return true;
}
else
{
return false;
}
}
bool s4(const Student &a, const Student &b) //比较 a b 总分 b大返回true
{
if(a.score[0]+a.score[1]+a.score[2]+a.score[3]>b.score[0]+b.score[1]+b.score[2]+b.score[3])
{
return true;
}
else if((a.score[0]+a.score[1]+a.score[2]+a.score[3]==b.score[0]+b.score[1]+b.score[2]+b.score[3])&&(a.num<b.num))
{
return true;
}
else
{
return false;
}
}
int select(Student st[],int n,bool (*s)(const Student &a,const Student &b))//挑选人数的分数最高的一个 用for循环
{
int maxmax=0,i;//先定义初始值
for(i=1; i<n; i++)//用for 循环比较 分数最多的那个
{
if(s(st[maxmax],st[i]))
{
continue;//相等的 话 持续 进行for循环
}
else
{
maxmax=i;
}
}
return st[maxmax].num;
}