• 金牌、铜牌、银牌


    金牌、银牌、铜牌

    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 typedef struct Node
      5 {
      6     char name[10];
      7     int score;
      8     struct Node *next;
      9 } node;
     10 struct listt
     11 {
     12     char name[10];
     13     int score;
     14 } a[1001];
     15 node *head,*tail;
     16 void inser(char s[],int sscore)
     17 {
     18     node *r,*p,*q;
     19     p = (node *)malloc(sizeof(node));
     20     strcpy(p->name,s);
     21     p->score = sscore;
     22     r = head;
     23     q = head->next;
     24     while(!(r->next == NULL||p->score > q->score))
     25     {
     26         r = r->next;
     27         q = q->next;
     28     }
     29     r->next = p;
     30     p->next = q;
     31 
     32 }
     33 void del()
     34 {
     35     char s[10];
     36     node  *q,*p;
     37     p = (node*)malloc(sizeof(node));
     38     scanf("%s%*c",p->name);
     39     q = head;
     40     while(q->next)
     41     {
     42         if(strcmp(q->next->name,p->name) == 0)
     43         {
     44             q->next = q->next->next;
     45             break;
     46         }
     47         q = q->next;
     48     }
     49 }
     50 void add()
     51 {
     52     node *p,*q,*r,*tmp;
     53     int m;
     54     p = (node *)malloc(sizeof(node));
     55     scanf("%s %d",p->name,&m);
     56     r = head;
     57     q = head->next;
     58     while(!(r->next == NULL || strcmp(q->name,p->name) == 0))
     59     {
     60         r = r->next;
     61         q = q->next;
     62     }
     63     tmp = q;
     64     inser(tmp->name,tmp->score+m);
     65     r->next = tmp->next;
     66     free(tmp);
     67 }
     68 void output()
     69 {
     70     node *q;
     71     q = head->next;
     72     while(q)
     73     {
     74         printf("%s %d
    ",q->name,q->score);
     75         q = q->next;
     76     }
     77 }
     78 void print(node *head)
     79 {
     80     node *p;
     81     p = head->next;
     82     int i =0;
     83     while(p)
     84     {
     85         strcpy(a[i].name,p->name);
     86         a[i].score = p->score;
     87         i++;
     88         p = p->next;
     89     }
     90     printf("#1 :");
     91     int j = 0,k;
     92     k = j;
     93     printf(" %s",a[j++].name);
     94     while(a[j++].score == a[k].score)
     95         printf(" %s",a[j].name);
     96     printf("
    #2 :");
     97     for(int cnt = 2; cnt > 0 && j < i; cnt--)
     98     {
     99         k = j;
    100         printf(" %s",a[j++].name);
    101         while(a[j].score == a[k].score)
    102             printf(" %s",a[j].name);
    103     }
    104     printf("
    #3 :");
    105     for(int cnt = 3; cnt > 0 && j < i; cnt--)
    106     {
    107         k = j;
    108         printf(" %s",a[j++].name);
    109         while(a[j].score == a[k].score)
    110             printf(" %s",a[j].name);
    111     }
    112     printf("
    ");
    113 }
    114 int main()
    115 {
    116     int n,sscore;
    117     char s[10];
    118     node *p;
    119     head = (node *)malloc(sizeof(node));
    120     head->next = NULL;
    121     tail = head;
    122     scanf("%d%*c",&n);
    123     while(n--)
    124     {
    125         p = (node *)malloc(sizeof(node));
    126         scanf("%s %d",p->name,&p->score);
    127         p->next = NULL;
    128         tail->next = p;
    129         tail = p;
    130     }
    131     char ch;
    132     while(scanf("%c%*c",&ch) != EOF)
    133     {
    134         if(ch == 'A')
    135         {
    136             scanf("%s %d%*c",s,&sscore);
    137             inser(s,sscore);
    138         }
    139         else if(ch == 'Q')
    140         {
    141             del();
    142         }
    143         else if(ch == 'C')
    144         {
    145             add();
    146         }
    147         else if(ch == 'S')
    148         {
    149             output();
    150             printf("
    ");
    151         }
    152         else if(ch == 'O')
    153         {
    154             print(head);
    155             break;
    156         }
    157     }
    158     return 0;
    159 }
      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<string.h>
      4 typedef struct Node
      5 {
      6     char name[10];
      7     int score;
      8     struct Node *next;
      9 } node;
     10 struct listt
     11 {
     12     char name[10];
     13     int score;
     14 } a[1001];
     15 node *inser(node *head)
     16 {
     17     node *p,*q;
     18     int f = 0;
     19     p = (node*)malloc(sizeof(node));
     20     scanf("%s %d",p->name,&p->score);
     21     q = head;
     22     while(q->next)
     23     {
     24         if(p->score > q->next->score)
     25         {
     26             p->next = q->next;
     27             q->next = p;
     28             f = 1;
     29             break;
     30         }
     31         q = q->next;
     32     }
     33     if(f == 0)
     34     {
     35         q = head;
     36         while(q->next != NULL)
     37             q =q->next;
     38         p->next = NULL;
     39         q->next = p;
     40         q = p;
     41     }
     42     return  head;
     43 }
     44 node *del(node *head)
     45 {
     46     node *q;
     47     char s[10];
     48     scanf("%s",s);
     49     q = head;
     50     while(q->next)
     51     {
     52         if(strcmp(q->next->name,s) == 0)
     53         {
     54             q->next = q->next->next;
     55             break;
     56         }
     57         q = q->next;
     58     }
     59     return head;
     60 }
     61 node *add(node *head)
     62 {
     63     node *p,*q,*t;
     64     p = (node*)malloc(sizeof(node));
     65     scanf("%s %d",p->name,&p->score);
     66     q = head;
     67     while(q->next)
     68     {
     69         if(strcmp(q->next->name,p->name) == 0)
     70         {
     71             t = q->next;
     72             t->score += p->score;
     73             q->next = q->next->next;
     74             break;
     75         }
     76         q = q->next;
     77     }
     78     q = head;
     79     while(q->next)
     80     {
     81         if(t->score > q->next->score)
     82         {
     83             t->next = q->next;
     84             q->next = t;
     85             break;
     86         }
     87         q = q->next;
     88     }
     89     return head;
     90 }
     91 void output(node *head)
     92 {
     93     node *p;
     94     p = head->next;
     95     while(p)
     96     {
     97         printf("%s %d
    ",p->name,p->score);
     98         p = p->next;
     99     }
    100 }
    101 void print(node *head)
    102 {
    103     int cnt;
    104     node *p;
    105     p = head->next;
    106     cnt = 0;
    107     while(p)
    108     {
    109         strcpy(a[cnt].name,p->name);
    110         a[cnt].score = p->score;
    111         cnt++;
    112         p = p->next;
    113     }
    114     printf("#1 :");
    115     int i,j;
    116     i = 0;
    117     j = i;
    118     printf(" %s",a[i++].name);
    119     while(a[i].score == a[j].score)
    120     {
    121         printf(" %s",a[i].name);
    122         i++;
    123     }
    124     printf("
    #2 :");
    125     for(int c = 2; c>0 && i < cnt; c--)
    126     {
    127         j = i;
    128         printf(" %s",a[i++].name);
    129         while(a[i].score == a[j].score)
    130         {
    131             printf(" %s",a[i].name);
    132             i++;
    133         }
    134     }
    135     printf("
    #3 :");
    136     for(int c = 3; c>0 && i < cnt; c--)
    137     {
    138         j = i;
    139         printf(" %s",a[i++].name);
    140         while(a[i].score == a[j].score)
    141         {
    142             printf(" %s",a[i].name);
    143             i++;
    144         }
    145     }
    146     printf("
    ");
    147 }
    148 int main()
    149 {
    150     node *head,*tail,*p,*q;
    151     int n;
    152     scanf("%d",&n);
    153     head = (node*)malloc(sizeof(node));
    154     head->next = NULL;
    155     tail = head;
    156     int f ;
    157     while(n--)
    158     {
    159         p = (node*)malloc(sizeof(node));
    160         f = 0;
    161         scanf("%s %d",p->name,&p->score);
    162         q = head;
    163         while(q->next)
    164         {
    165             if(p->score > q->next->score)
    166             {
    167                 p->next = q->next;
    168                 q->next = p;
    169                 f = 1;
    170                 break;
    171             }
    172             q = q->next;
    173         }
    174         if(f == 0)
    175         {
    176             p->next = NULL;
    177             tail->next= p;
    178             tail = p;
    179         }
    180     }
    181     char ch;
    182     while(~scanf("%c",&ch))
    183     {
    184         if(ch == 'A')
    185         {
    186             head = inser(head);
    187         }
    188         else if(ch == 'Q')
    189         {
    190             head = del(head);
    191         }
    192         else if(ch == 'C')
    193         {
    194             head = add(head);
    195         }
    196         else if(ch == 'S')
    197         {
    198             output(head);
    199             printf("
    ");
    200         }
    201         else if(ch == 'O')
    202         {
    203             print(head);
    204             break;
    205         }
    206     }
    207     return 0;
    208 }
    View Code

     下面写的这个比较清晰、

  • 相关阅读:
    关于JavaScript文档对象
    关于JavaScript浏览器对象
    关于JavaScript事件与函数
    关于JavaScript基础知识
    关于CSS基础知识
    第七章:Hexadecimal, octal, ASCII, UTF8, Unicode, Runes
    没有 Cgroups,就没有 Docker
    Redis 文件事件
    Python 垃圾回收总结
    Docker Bridge 网络原理
  • 原文地址:https://www.cnblogs.com/LK1994/p/3143493.html
Copyright © 2020-2023  润新知