SDUT 2057 金牌、银牌、铜牌

本来是在链表里的比赛,可是我没用链表,主要是链表不会排序......

最后输出奖项的时候卡了好长时间,最后还是问的芳姐 · - · 

本来是150ms的,去掉几个没用的排序之后,成10ms了,还是跑秒了=_=!

/**************************************
 Problem id : SDUT OJ J
 User name : Silence—Debug
 Result  : Accepted
 Take Memory : 1328K
 Take Time : 10MS
 Submit Time : 2013-03-20 20:28:08 
**************************************/

# include <stdio.h>
# include <string.h>
# include <stdlib.h>

struct node
{
    char s[1000];
    int score;
    int p;
} a[1000];

int cmp(const void *x, const void *y)
{
    return ((struct node *)y) -> score - ((struct node *)x) -> score;
}

int main(void)
{
    int i, t, n, j, prize, f;
    char ch, str[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%s %d", a[i].s, &a[i].score);
    while(~scanf("%c", &ch))
    {
        if(ch == 'O')
            break;
        else if(ch == 'S')
        {
            qsort(a, n, sizeof(struct node), cmp);
            for(i = 0; i < n; i++)
            {
                if(a[i].score != 0)
                    printf("%s %d\n", a[i].s, a[i].score);
            }
        }
        else if(ch == 'A')
        {
            scanf("%s%d", str, &t);
            strcpy(a[n].s, str);
            a[n].score = t;
            n++;
        }
        else if(ch == 'Q')
        {
            scanf("%s", str);
            getchar();
            for(i = 0; i < n; i++)
                if(strcmp(a[i].s, str) == 0)
                    a[i].score = 0;
        }
        else if(ch == 'C')
        {
            scanf("%s%d", str, &t);
            for(i = 0; i < n; i++)
                if(strcmp(a[i].s, str) == 0)
                    a[i].score += t;
        }
    }
    qsort(a, n, sizeof(struct node), cmp);
    prize = 2;
    f = 1;
    j = 0;
    printf("#1 :");
    for(i = 0; i < n; i++)
    {
        if(a[i].score == a[j].score)
            printf(" %s", a[i].s);
        else
        {
            f++;
            j = i;
            if(f == 2 || f == 4)
            {
                puts("");
                printf("#%d :", prize++);
            }
            if(f == 7)
                break;
            printf(" %s", a[i].s);
        }
    }

    return 0;
}
View Code

 

 

转载于:https://www.cnblogs.com/Silence-AC/archive/2013/03/20/2971862.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值