LianYan @ 2023-11-04 20:01:09
#include <stdio.h>
int main()
{
long sco[305][4]={0};
int n,i,t,num=0;
long max[2]={0};
scanf("%d",&n);
for ( i = 0; i < n; i++)//0是语文,1是数学,2是英语,3是总分
{
for ( t = 0; t < 3; t++)
{
scanf("%d",&sco[i][t]);
sco[i][3]+=sco[i][t];
}
}
for ( t = 0; t < 5; t++)//循环输出5个人
{
max[1]=0;
max[0]=0;
for ( i = n-1; i >=0; i--)//从后往前开始比较,确保if判断都是相等时输出学号小的
{
if(sco[i][3]>=max[1]&&sco[i][0]>=max[0])//总分大于等于,语文大于等于,
{
max[1]=sco[i][3];
max[0]=sco[i][0];
num=i;
}else
{
continue;
}
}
printf("%d %ld\n",num+1,sco[num][3]);//遍历过后找到的num就是数组序号
sco[num][3]=0;//避免再次比较 __
sco[num][0]=0;
}
return 0;
}
就过了1和5
by a1422612 @ 2023-11-25 21:45:17
if判断有问题,应该先只比较总分,总分相同再比较语文成绩