金牌银牌铜牌

花了三个小时写成的代码。。。。呼。。。累死了。。。

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 typedef struct Node
  5 {
  6     char s[10];
  7     int data;
  8     struct Node *next;
  9 } node;
 10 struct lode
 11 {
 12     char s[10];
 13     int data;
 14 };
 15 node *head;
 16 
 17 void inter(char e[],int h)
 18 {
 19     node *t,*p,*p1;
 20     t=(node *)malloc(sizeof(node));
 21     strcpy(t->s,e);
 22     t->data=h;
 23     p1=head;
 24     p=head->next;
 25     while(!(p1->next==NULL||t->data>p->data))
 26     {
 27         p1=p1->next;
 28         p=p->next;
 29     }
 30     t->next=p;
 31     p1->next=t;
 32 }
 33 void add(node *head)
 34 {
 35     node *p1,*p,*t,*q;
 36     int k;
 37     t=(node *)malloc(sizeof(node));
 38     scanf("%s %d%*c",t->s,&k);
 39     p1=head;
 40     p=head->next;
 41     while(!(p1->next==NULL||strcmp(t->s,p->s)==0))
 42     {
 43         p1=p1->next;
 44         p=p->next;
 45     }
 46     q=p;
 47     inter(q->s,q->data+k);
 48     p1->next=q->next;
 49     free(q);
 50 }
 51 void out(node *head)
 52 {
 53     node *q,*p;
 54     p=(node *)malloc(sizeof(node));
 55     scanf("%s%*c",p->s);
 56     q=head;
 57     while(q->next!=NULL)
 58     {
 59         if(strcmp(q->next->s,p->s)==0)
 60         {
 61             q->next=q->next->next;
 62         }
 63         else
 64             q=q->next;
 65     }
 66 }
 67 void outall(node *head)
 68 {
 69     node *p;
 70     p=head->next;
 71     while(p!=NULL)
 72     {
 73         printf("%s %d\n",p->s,p->data);
 74         p=p->next;
 75     }
 76 }
 77 void list(node *head)
 78 {
 79     node *q;
 80     struct lode a[10000];
 81     int i;
 82     q=head->next;
 83     i=0;
 84     while(q!=NULL)
 85     {
 86         strcpy(a[i].s,q->s);
 87         a[i].data=q->data;
 88         i++;
 89         q=q->next;
 90     }
 91     int j=0,k,ss;
 92     printf("#1 :");
 93     k=j;
 94     printf(" %s",a[j++].s);
 95     while(a[j].data==a[k].data)
 96     {
 97         printf(" %s",a[j].s);
 98         j++;
 99     }
100     printf("\n#2 :");
101     for(ss=2; ss>0&&j<i; ss--)
102     {
103         k=j;
104         printf(" %s",a[j++].s);
105         while(a[j].data==a[k].data)
106         {
107             printf(" %s",a[j++].s);
108         }
109     }
110     printf("\n#3 :");
111     for(ss=3; ss>0&&j<i; ss--)
112     {
113         k=j;
114         printf(" %s",a[j++].s);
115         while(a[j].data==a[k].data)
116         {
117             printf(" %s",a[j++].s);
118         }
119     }
120 }
121 int main()
122 {
123     node *p,*t,*p1;
124     char e[100];
125     int h;
126     head=(node *)malloc(sizeof(node));
127     head->next=NULL;
128     int n;
129     char k;
130     scanf("%d%*c",&n);
131     while(n--)
132     {
133         t=(node *)malloc(sizeof(node));
134         scanf("%s %d%*c",t->s,&t->data);
135         t->next=NULL;
136         p1=head;
137         p=head->next;
138         while(!(p1->next==NULL||t->data>p->data))
139         {
140             p1=p1->next;
141             p=p->next;
142         }
143         t->next=p;
144         p1->next=t;
145     }
146     while(scanf("%c%*c",&k)!=EOF)
147     {
148          if(k=='A')
149         {
150             t=(node *)malloc(sizeof(node));
151            scanf("%s %d%*c",e,&h);
152             inter(e,h);
153         }
154         else if(k=='Q')
155         {
156             out(head);
157         }
158         else if(k=='C')
159         {
160             add(head);
161         }
162         else if(k=='S')
163         {
164             outall(head);
165             printf("\n");
166         }
167         else if(k=='O')
168         {
169             list(head);
170             break;
171         }
172     }
173 
174     return 0;
175 }

 

转载于:https://www.cnblogs.com/mafangfang/archive/2013/04/02/2996682.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值