Title description
There is a student transcript, including student number, name, and grades of 3 courses. Please sort according to the following rules: sort in descending order by total score, if the total score is the same, sort in ascending order by name.
enter
First enter an integer n (1<=n<=100), indicating the number of students;
then enter n lines, each line contains a student's information: student ID (12 digits), name (no spaces and no more than 20 digits) , And 3 integers, representing the results of 3 courses, separated by spaces.
Output
The sorted transcript is output, the format is shown in the output sample.
Sample input
3
541207010188 Zhangling 89 78 95
541207010189 Wangli 85 87 99
541207010190 Fangfang 89 88 85
Sample input
541207010189 Wangli 85 87 99 271
541207010190 Fangfang 89 88 85 262
541207010188 Zhangling 89 78 95 262
Sample output
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char num[50];
char name[50];
int x,y,z;
}student;
int main()
{
int t;
int i,j,s1,s2;
student a[150],m;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%s%s%d%d%d",a[i].num,a[i].name,&a[i].x,&a[i].y,&a[i].z);
}
for(i=1;i<t;i++)
{
for(j=0;j<t-i;j++)
{
if((a[j].x+a[j].y+a[j].z)<(a[j+1].x+a[j+1].y+a[j+1].z))
{
m=a[j];
a[j]=a[j+1];
a[j+1]=m;
}
else if((a[j].x+a[j].y+a[j].z)==(a[j+1].x+a[j+1].y+a[j+1].z))
{
if(strcmp(a[j].name,a[j+1].name)>0)
{
m=a[j];
a[j]=a[j+1];
a[j+1]=m;
}
}
}
}
for(i=0;i<t;i++)
{
printf("%s %s %d %d %d %d\n",a[i].num,a[i].name,a[i].x,a[i].y,a[i].z,a[i].x+a[i].y+a[i].z);
}
return 0;
}