码迷,mamicode.com
首页 > 其他好文 > 详细

杭电oj1004 自写成功代码

时间:2015-03-31 00:29:39      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

#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]=‘\0‘;
for(j=head;j!=NULL;j=j->next){
if(j->num>max){
max=j->num;
strcpy(b,j->name);
}
}
printf("%s\n",b);

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

}
head->next=NULL;
}

return 0;
}

杭电oj1004 自写成功代码

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!