金牌、银牌、铜牌(C语言)

来源:互联网 发布:穿越火线mac官方下载 编辑:程序博客网 时间:2024/04/27 14:58
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct ns
{
    char name[21];
    int m;
    struct ns *next;
};
struct ns *scan(int n)
{
    int i;
    struct ns *head,*tail,*p;
    head=malloc(sizeof(struct ns));
    head->next=NULL;
    tail=head;
    for(i=0;i<n;i++)
    {
        p=malloc(sizeof(struct ns));
        scanf("%s%d",p->name,&p->m);
        p->next=NULL;
        tail->next=p;
        tail=p;
    }
    return head;
}
void a(struct ns *head,struct ns *p)
{
    struct ns *t;
    /*p=malloc(sizeof(struct ns));
    p->next=NULL;
    scanf("%s%d",p->name,&p->m);*/
    t=head;
    while(t->next!=NULL)
    {
        if(t->next->m>=p->m)
            t=t->next;
        else
            break;
    }
    p->next=t->next;
    t->next=p;
}
void q(struct ns *head)
{
    char name[21];
    struct ns *t;
    t=head;
    scanf("%s",name);
    while(t->next!=NULL)
    {
        if(strcmp(t->next->name,name)==0)
        {
            t->next=t->next->next;break;
        }
        t=t->next;
    }
}
void c(struct ns *head)
{
    char name[21];
    int x;
    struct ns *t,*m;
    scanf("%s%d",name,&x);
    t=head;
    while (t->next!=NULL)
    {
        if(strcmp(t->next->name,name)==0)
        {
            m=t->next;
            t->next=t->next->next;break;
        }
        t=t->next;
    }
    m->next=NULL;m->m=m->m+x;
    //printf("c%d",m->m);
    a(head,m);
}
void s(struct ns *head)
{
    struct ns *p;
    p=head->next;
    while (p!=NULL)
    {
        printf("%s %d\n",p->name,p->m);
        p=p->next;
    }
}
void o(struct ns *head,int paiming)
{
    if(paiming==4)
        return ;
    int i,t;
    struct ns *p;
    p=head;
    printf("#%d : %s",paiming,p->name);
    i=1;
    t=p->m;
    p=p->next;
    while(p!=NULL)
    {
        if(p->m==t&&i<=paiming)
        {
            printf(" %s",p->name);
            t=p->m;
            p=p->next;
        }
        else if(p->m!=t&&i<paiming)
        {
            printf(" %s",p->name);
            t=p->m;
            p=p->next;
            i++;
        }
        else
            break;
    }
    printf("\n");
    paiming=paiming+1;
    o(p,paiming);
}
int main()
{
    int n;
    char ch;
    struct ns *head,*p;
    scanf("%d",&n);
    head=scan(n);
    while(scanf("%c",&ch)!=EOF)
    {
        if(ch=='O')
            {o(head->next,1);break;}
        if(ch=='A')
        {
            p=malloc(sizeof(struct ns));
            p->next=NULL;
            scanf("%s%d",p->name,&p->m);
            a(head,p);
        }
        if(ch=='Q')
            q(head);
        if(ch=='C')
            c(head);
        if(ch=='S')
            s(head);
    }
    return 0;
}
0 0
原创粉丝点击