C 最终排名 SDUT

Time Limit: 1000 ms Memory Limit: 65536 KiB


Problem Description

第四届山东理工大学ACM网络编程擂台赛比赛完后需要产生一个最终排名,排名按照题数多少来决定。但是有太多的队伍参与,手动计算排名已经不能满足比赛的需求。现在有一份名单记录各个队伍的ID和做出的题目数,需要你写一个程序,产生最终的排名。
为了简化题目,这里的排名规则为:做出题目数量多的队伍排在前面,如果题数相等,保持输入时的相对顺序不要改变。


Input

第一行包含一个正整数T( 1 ≤ T ≤ 15),表示有T组测试数据。每组数据第一行有一个正整数N(1 < N ≤ 10000),表示队伍数量。接下来N 行包含两个整数,1 ≤ ID ≤ 10^7, 0 ≤ M ≤ 100。ID为队伍的编号,M为做出的题数。


Output

每组数据输出包含N行,第i行有两个整数,ID和M表示排在第i位的队伍的ID和做出的题数。


Sample Input

1
8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4


Sample Output

3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1


Hint

Source


代码一

#include <stdio.h>
#include <stdlib.h>
struct node
{
    int score;
    int id;
}a[100000];


void putin(struct node a[],int n);
void storing_score(struct node a[],int n);
void putout(struct node a[],int n);


int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        putin(a,n);
        storing_score(a,n);
        putout(a,n);
    }

    return 0;
}


void putin(struct node a[],int n)
{
    int i;
    for(i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].id,&a[i].score);
        }
}


void storing_score(struct node a[],int n)
{
    int i,j;
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(a[j].score<a[j+1].score)
            {
                struct node t = a[j];
                a[j] = a[j+1];
                a[j+1] = t;
            }
        }
    }
}


void putout(struct node a[],int n)
{
    int i;
    for(i=0;i<n;i++)
    printf("%d %d\n",a[i].id,a[i].score);
}

代码二:

#include <stdio.h>
#include <stdlib.h>
struct
{
    int id;
    int score;
}team[10001];
//定义时比最大范围还大一,最后一个作为下面交换时的中间变量;
int main()
{
int t;
int n,i,j;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
    scanf("%d",&n);
    for(j=0;j<n;j++)//输入;
    scanf("%d%d",&team[j].id,&team[j].score);
    int k;
     for(k=0;k<n;k++)//排序;
    {
        for(j=0;j<n-k-1;j++)
        {
            if(team[j].score<team[j+1].score)
            {
              team[10001]=team[j];
                team[j]=team[j+1];
                team[j+1]=team[10001];
            }
        }
    }//排序,这里采用冒泡排序的思路;
    for(j=0;j<n;j++)
        printf("%d %d\n",team[j].id,team[j].score);
}

    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

碧羽o(* ̄▽ ̄*)ブ回雪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值