杭电oj1004 自写成功代码

#include<stdio.h>
#include<malloc.h>
#include<string.h>


typedef struct Color{
char name[16];
int num;
struct Color *next;
}Color,*COLOR;

void Init(Color *head){
char a[16]="0";
head->next=NULL;
strcpy(head->name,a);
head->num=0;
}
int main(){
int n;
int max;
int panduan;
Color *i;
Color *j;
Color *t;
COLOR head;
char a[16];
char b[16];
head=j=(Color *)malloc(sizeof(Color));
Init(j);
while(scanf("%d",&n)!=EOF&&n!=0){
while(n--){
scanf("%s",a);

for(i=head,panduan=0;i!=NULL;i=i->next){
if(strcmp(i->name,a)==0){
panduan=1;
i->num++;
break;
}
t=i;
}
if(panduan==0){
j=(Color *)malloc(sizeof(Color));
strcpy(j->name,a);
j->num=1;
t->next=j;
j->next=NULL;
}
}
max=0;
b[0]='';
for(j=head;j!=NULL;j=j->next){
if(j->num>max){
max=j->num;
strcpy(b,j->name);
}
}
printf("%s ",b);

for(j=head->next;j!=NULL;){
i=j;
j=j->next;
free(i);

}
head->next=NULL;
}

return 0;
}

原文地址:https://www.cnblogs.com/ganeveryday/p/4379454.html