• 金牌银牌铜牌


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

      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 }
  • 相关阅读:
    线程笔记
    值类型与引用类型
    abstract抽象 抽象方法 不能有实现{} 0907
    接口
    结构
    XML初探
    javaScript中为什么会有变量提升?
    Windows 7实现自动登录(本地账户和域账户)
    WCF 提示 "由于正在读取的 XML 数据的嵌套级比配额所允许的多,因此已超出最大读取深度 (32)" 的解决办法
    也来安个家!
  • 原文地址:https://www.cnblogs.com/mafangfang/p/2996682.html
Copyright © 2020-2023  润新知