题目1196:成绩排序

题目1196:成绩排序
 

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:5219

解决:1802

题目描述:

用一维数组存储学号和成绩,然后,按成绩排序输出。

输入:

输入第一行包括一个整数N(1<=N<=100),代表学生的个数。
接下来的N行每行包括两个整数p和q,分别代表每个学生的学号和成绩。

输出:

按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来。
如果学生的成绩相同,则按照学号的大小进行从小到大排序。

样例输入 3
1 90
2 87
3 92
样例输出: 2 87
1 90
3 92
来源:
2009年华中科技大学计算机研究生机试真题
代码:#include "stdio.h"
struct student
{
      int id;
      int score;
};
void sort(struct student stu[],int n)      //对学生进行排序
{
      struct student temp;        //临时存放id和score
      int i,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;
                    }
            }
        }
    }
    for(i=0; i<=n-1; i++)
    {
        printf("%d %d\n",stu[i].id,stu[i].score);
    }
}
int main()
{
    int n,i=0;
    struct student stu[101];
    while(scanf("%d",&n)!=EOF)        //n代表学生数量
    {
        for(i=0; i小于n;i++)
        {
            scanf("%d%d",&stu[i].id,&stu[i].score);
        }
        sort(stu,n);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值