zoukankan      html  css  js  c++  java
  • 金牌、银牌、铜牌

    金牌、银牌、铜牌

    Time Limit: 1000MS Memory limit: 65536K

    题目描述

    Acm——大学中四大竞赛之首——是极具挑战性的大学生竞赛形式。在一场acm比赛中,一个参赛队伍由三人组合而成,在最短的时间内做出尽可能多的题目而且要尽量少提交错误代码,这样才能得到更高的排名。现在让我们模拟一次不正规的acm比赛,假设在比赛开始后30分钟(这时已经有不少同学提交了代码,在rating中已经出现),到比赛结束前,又有新的同学提交(在rating中出现),同时rating在不断变化着,还有一些同学因为一些原因中途退出比赛(这时rating中自动删除,当然在正式比赛中不会有这种情况)。最后终于比赛结束啦,看看rating,都有谁能拿到奖牌呢?

    输入

    第一行一个整数n(n<=1000),代表开始比赛后30分钟已经有n个人提交了代码。从第二行到第n+1行每行包括名字name(小于20个字符),分数p(0<=p<=10000),同时行数代表目前排名情况,第二行的排名第一,第三行排名第二,依次类推。

    从第n+2行起,每行有一个字符,是A,Q,C,S,O中的一个:

    A代表新加进rating中一名同学,紧随其后是名字name(小于20个字符),分数p(0<=p<=10000);

    Q代表有一名同学退出了,接着是他的名字name(小于20个字符);

    C代表有一个人的分数发生的改变,接着是此人的名字name,他的分数加多少(分数只会增加不会减少);

    S代表一次显示此时rating的请求,这时输出所有在rating中的同学名字及他们的分数。

    O代表比赛结束。

    输出

    对每次请求,输出此时rating中的所有同学名字和对应分数,并输出一个空行,在比赛结束时输出金牌获得者(一名),银牌获得者(两名),铜牌获得者(三名)(测试数据保证此时有至少6名同学在rating上)。如果分数相同的则并列为相同奖。更详细的输出见示例。

    示例输入

    7
    cze 90
    qch 87
    zff 70
    shangcf 66
    zhaohq 50
    zhrq 46
    yah 20
    A pc 56
    Q zff
    C qch 4
    S
    A von 66
    O
    

    示例输出

    qch 91
    cze 90
    shangcf 66
    pc 56
    zhaohq 50
    zhrq 46
    yah 20
    
    #1 : qch
    #2 : cze shangcf von
    #3 : pc zhaohq zhrq

      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<string.h>
      4 struct vode
      5 {
      6      char f[30];
      7     int date;
      8     struct vode *next;
      9 };
     10 int main()
     11 {
     12     int n;
     13     scanf("%d",&n);
     14     struct vode *head,*tail,*p,*q;
     15     head=(struct vode *)malloc(sizeof(struct vode ));
     16     head->next=NULL;
     17     tail=head;
     18     int i;
     19     for(i=1;i<=n;i++)
     20     {
     21         p=(struct vode *)malloc(sizeof(struct vode));
     22         p->next=NULL;
     23         scanf("%s%d",p->f,&p->date);
     24         tail->next=p;
     25         tail=p;
     26      }
     27     char a;
     28     while(~scanf("%c",&a))
     29     {
     30         int k;
     31         char g[30];
     32         int data;
     33         if(a=='A')
     34         {
     35             scanf("%s%d",g,&data);
     36             p=(struct vode *)malloc(sizeof(struct vode));
     37             p->next=NULL;
     38             strcpy(p->f,g);
     39             p->date=data;
     40             tail->next=p;
     41             tail=p;
     42         }
     43         if(a=='Q')
     44         {
     45             scanf("%s",g);
     46             p=head;
     47             while(p->next)
     48             {
     49                 q=p->next;
     50                 if(strcmp(q->f,g)==0)
     51                 {
     52                    p->next=q->next;
     53                 }
     54                 else
     55                 {
     56                     p=p->next;
     57                     q=q->next;
     58                 }
     59             }
     60             tail=head;
     61             while(tail->next)
     62             tail=tail->next;
     63         }
     64         if(a=='C')
     65         {
     66             scanf("%s%d",g,&data);
     67             p=head->next;
     68             while(p)
     69             {
     70                 if(strcmp(g,p->f)==0)
     71                 {
     72                     p->date=p->date+data;
     73                 }
     74                 p=p->next;
     75             }
     76         }
     77         if(a=='O')
     78         {
     79             k=0;
     80             while(k=!k)
     81             {
     82                 p=head->next;
     83                 q=p->next;
     84                 while(q)
     85                 {
     86                     if(p->date<q->date)
     87                     {
     88                         int t;
     89                         char gh[30];
     90                         strcpy(gh,p->f);
     91                         strcpy(p->f,q->f);
     92                         strcpy(q->f,gh);
     93                         t=p->date;
     94                         p->date=q->date;
     95                         q->date=t;
     96                         k=0;
     97                     }
     98                     else
     99                     {
    100                         p=p->next;
    101                         q=q->next;
    102                     }
    103                 }
    104             }
    105             printf("#1 :");
    106             p=head->next;
    107             while(p->next)
    108             {
    109                 q=p->next;
    110                 if(p->date==q->date)
    111                     printf(" %s",p->f);
    112                 else
    113                 {
    114                     printf(" %s",p->f);
    115                     break;
    116                 }
    117                 p=p->next;
    118             }
    119             printf("
    #2 :");
    120             p=q;
    121             while(p->next)
    122             {
    123                   q=p->next;
    124                 if(p->date==q->date)
    125                     printf(" %s",p->f);
    126                 else
    127                 {
    128                     printf(" %s",p->f);
    129                     break;
    130                 }
    131                 p=p->next;
    132             }
    133             p=q;
    134             while(p->next)
    135             {
    136                   q=p->next;
    137                 if(p->date==q->date)
    138                     printf(" %s",p->f);
    139                 else
    140                 {
    141                     printf(" %s",p->f);
    142                     break;
    143                 }
    144                 p=p->next;
    145             }
    146             printf("
    #3 :");
    147             p=q;
    148             while(p->next)
    149             {
    150                   q=p->next;
    151                 if(p->date==q->date)
    152                     printf(" %s",p->f);
    153                 else
    154                 {
    155                     printf(" %s",p->f);
    156                     break;
    157                 }
    158                 p=p->next;
    159             }
    160             p=q;
    161             while(p->next)
    162             {
    163                   q=p->next;
    164                 if(p->date==q->date)
    165                     printf(" %s",p->f);
    166                 else
    167                 {
    168                     printf(" %s",p->f);
    169                     break;
    170                 }
    171                 p=p->next;
    172             }
    173             p=q;
    174             while(p->next)
    175             {
    176                   q=p->next;
    177                 if(p->date==q->date)
    178                     printf(" %s",p->f);
    179                 else
    180                  {
    181                     printf(" %s",p->f);
    182                     break;
    183                 }
    184                 p=p->next;
    185             }
    186             printf("
    ");
    187             break;
    188         }
    189         if(a=='S')
    190         {
    191 
    192             k=0;
    193             while(k=!k)
    194             {
    195                 p=head->next;
    196                 q=p->next;
    197                 while(q)
    198                 {
    199                     if(p->date<q->date)
    200                     {
    201                         int t;
    202                         char gh[30];
    203                         strcpy(gh,p->f);
    204                         strcpy(p->f,q->f);
    205                         strcpy(q->f,gh);
    206                         t=p->date;
    207                         p->date=q->date;
    208                         q->date=t;
    209                         k=0;
    210                     }
    211                     else
    212                     {
    213                         p=p->next;
    214                         q=q->next;
    215                     }
    216                 }
    217             }
    218            p=head->next;
    219            int sn=0;
    220            while(p)
    221            {
    222                if(sn==0)
    223                {
    224                    printf("%s %d
    ",p->f,p->date);
    225                    sn=1;
    226                }
    227                else
    228                {
    229                    printf("%s %d
    ",p->f,p->date);
    230                }
    231                p=p->next;
    232            }
    233            printf("
    ");
    234         }
    235     }
    236     return 0;
    237 }
    View Code
  • 相关阅读:
    Java 构造方法总结
    Intellij IDEA使用总结
    阿里巴巴Java开发手册
    灰度发布策略
    php redis 命令合集
    php redis 常用方法
    php excel 设置单元格格式为文本格式
    php curl get post 方法的封装
    PHP 判断手机号归属地 和 运营商的免费接口
    lnmp centos7 memcache服务器端 和 memcache memcached扩展的安装
  • 原文地址:https://www.cnblogs.com/kuangdaoyizhimei/p/3264628.html
Copyright © 2011-2022 走看看