为什么一直是Wrong Answer啊,DescriptionThere are some students’ grade records,in format of “name grade”.In order to make the teacher to view and manage all the records easily,you areasked to develop a program to sort the records first by
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 19:22:47
为什么一直是Wrong Answer啊,DescriptionThere are some students’ grade records,in format of “name grade”.In order to make the teacher to view and manage all the records easily,you areasked to develop a program to sort the records first by
为什么一直是Wrong Answer啊,
Description
There are some students’ grade records,in format of “name grade”.
In order to make the teacher to view and manage all the records easily,you are
asked to develop a program to sort the records first by grade (in descending
order),and second by name (in alphabetic
order).That means the sorted records will be from the highest grade to lowest
grade; and if two students have the same grade,whose name appeared earlier in
a dictionary will be shown earlier.
Input
8 grade records,one record on per line.
Only letters and digits appear in the name of a student (i.e.therewill be no space in a name).All grades are integers.
Output
The 8 sorted records,one record per line.
Sample Input
WangYi 90
LiMing 90
HuRui 50
ZhangLi 65
LiLei 80
ZhangFei 65
ZhaoSan 70
ChenZi 100
Sample Output
ChenZi 100
LiMing 90
WangYi 90
LiLei 80
ZhaoSan 70
ZhangFei 65
ZhangLi 65
HuRui 50
#include
#include
int main()
{
typedef struct
{
char name[200];
int grade;
}Mess;
Mess a[8];
int t,i,j;
char q[200],s[200];
for(i=0;i
为什么一直是Wrong Answer啊,DescriptionThere are some students’ grade records,in format of “name grade”.In order to make the teacher to view and manage all the records easily,you areasked to develop a program to sort the records first by
算法错误.
for(i=0;i0)
{
strcpy(s,a[i].name);
strcpy(a[i].name,a[i+1].name);
strcpy(a[i+1].name,s);
}
没有正确排序.一层循环不是排序,只是交换邻位,应该两层嵌套循环,而且最好放在上面的那个两层循环里面更快.
而且正常做法,直接使用algorithm库的sort函数就可以了,没必要自己写排序.