题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1004
参考代码:
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
int i,n,j,max,tmp;
char ctmp[16];
while (scanf("%d",&n)&&n)
{
char (*p)[16] = (char(*)[16])malloc(sizeof(char)*n*16);
int *ip = (int*)malloc(sizeof(int)*n);
for (i=0;i<n;i++)
{
ip[i]=1;
}
for (i=0;i<n;i++)
{
scanf("%s",p[i]);
for (j=0;j<i;j++)
{
if (strcmp(p[i],p[j])==0)
{
ip[i]++;
}
}
}
for (i=0;i<n-1;i++)//下面两个循环是冒泡排序
{
for (j=i;j<n;j++)
{
if (ip[i]>ip[j])
{
tmp = ip[i];
ip[i] = ip[j];
ip[j] = tmp;
strcpy(ctmp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],ctmp);
}
}
}
printf("%s\n",p[n-1]);
}
}
下面是结果