题目1196:成绩排序
来源:互联网 发布:保密式网络机柜 编辑:程序博客网 时间:2024/05/30 23:53
- 题目1196:成绩排序
-
- 代码:#include "stdio.h"
struct student
{
intid;
intscore;
};
void sort(struct student stu[],intn)//对学生进行排序
{
structstudenttemp; //临时存放id和score
inti,j;
for(i=n-1;i>0; i--)
{
for(j=0; j小于i;i++)
{
if(stu[j].score>stu[j+1].score)
{
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
else if(stu[j].score==stu[j+1].score)
{
if(stu[j].id> stu[j + 1].id)
{
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;