Hdu 1004

//Problem:hdu1004
//Data:2011/10/30

#include <iostream>
using namespace std;

//颜色结构,num用来计算每种颜色出现的次数 
struct Color{
	int num;
	char color[16];	
};

Color input[1000] = {0,""};

//按降序排序 
int int_cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}

int main()
{
	//freopen("E:\\in.txt","r",stdin);
	int n,i,j;
	char temp[16];
	while(cin>>n,n!=0)
	{
		int count=0;
		bool exist;
		for(i=0; i<n; i++)
		{
			//每读入一个颜色,就判断是否之前出现过,如果出现过,就把exist标记为true,并把计数+1,然后立即break出循环 
			cin >> temp;
			exist = false;
			for(j=0; j<count; j++)
			{
				if(strcmp(temp,input[j].color) == 0)
				{
					exist = true;
					input[j].num++;
					break;
				}
			}
			//如果不存在,就把这种颜色加到数组中去,并使计数初始为0 
			if(!exist)
			{
				//input[count].color = temp;
				strcpy(input[count].color,temp);
				input[count].num = 0;
				count++;
			}
		}
		//对数组进行快速排序,排在第一个的就是数量最多的颜色,最后打印 
		qsort(input,count,sizeof(Color),int_cmp);
		cout << input[0].color << endl;		
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值