1004—Let the Balloon Rise

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1004

经验教训:这是道很水的题目,错因在于没考虑n=1的情况,所以,测试时应该多选一下边界值;有时也有可能是数组越界。。

 

 

我的代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct {     
	char str[16];    
}In;
In s[1005];  
int cmp ( const void *a , const void *b )    
{    
 return strcmp( (*(In *)a).str , (*(In *)b).str );    
}    
int main()
{int n;

while(scanf("%d",&n)&&n!=0)
{int i;

getchar();
for(i=0;i<n;i++)
gets(s[i].str);

qsort(s,n,sizeof(s[0]),cmp);

char *a,*b,*e;
int c,d;

c=1;
d=0;
if(n==1){e=s[0].str;}
else {for(i=0;i<n-1;i++)
{a=s[i].str;
b=s[i+1].str;
if(strcmp(a,b)==0&&i!=n-2)c++;
else {
if(i==n-2){
	if(strcmp(a,b)==0)c++;}
if(c>=d){d=c;c=1;e=a;}
else c=1;
}
}
}

printf("%s\n",e);
}

return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值