Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges'
favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
 
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total
number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
 
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed
that there is a unique solution for each test case.
 
Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
 
Sample Output
red
pink
--------------------------------------------------------------------------------------------------
/*
简单题,统计气球数最多的颜色
*/
#include <stdio.h>
#define SIZE_ROW 1001
#define SIZE_COL 16 int main()
{
int N;
int i; char colors[SIZE_ROW][SIZE_COL];
char color[SIZE_COL];
//存储气球颜色数
int colorNum;
//统计不同颜色气球个数
int balloon[SIZE_ROW];
//用于返回重复颜色气球的下标
int result;
//颜色对多的气球个数
int max;
//颜色最多的气球个数的下标
int maxIndex;
//freopen("F:\\input.txt", "r", stdin);
while ((scanf("%d", &N) == 1) && N != 0)
{
colorNum = 0;
memset(balloon, 0, sizeof(balloon));
memset(colors,0,sizeof(colors));
for (i = 0; i < N; i++)
{
scanf("%s", color);
//搜索颜色数组,如果没有当前输入的颜色,则将该颜色插入颜色数组。否则,对应的气球数+1
result = searchColor(color, colors, colorNum, balloon);
if (result == -1)
{
strcpy(colors[colorNum], color);
balloon[colorNum]++;
colorNum++;
}
else
balloon[result]++;
}
max = balloon[0];
maxIndex = 0;
//寻找气球数最多的颜色
for (i = 1; i < colorNum; i++)
{
if (max < balloon[i])
{
max = balloon[i];
maxIndex = i;
}
}
printf("%s\n", colors[maxIndex]);
}
//freopen("con", "r", stdin);
//system("pause");
return 0;
} int searchColor(char color[], char colors[][SIZE_COL], int colorNum, int balloon[])
{
int i;
for (i = 0; i < colorNum; i++)
{
if (strcmp(color, colors[i]) == 0)
return i;
}
return -1;
}

  

ACM1004:Let the Balloon Rise的更多相关文章

  1. Let the Balloon Rise 分类: HDU 2015-06-19 19:11 7人阅读 评论(0) 收藏

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  3. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. HDU1004 Let the Balloon Rise(map的简单用法)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  5. Let the Balloon Rise(map)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. HDU 1004 Let the Balloon Rise【STL<map>】

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. Let the Balloon Rise(水)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  8. hdu 1004 Let the Balloon Rise(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  9. hdu 1004 Let the Balloon Rise strcmp、map、trie树

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

随机推荐

  1. Error: A JNI error has occurred, please check your installation and try again

    自己写的maven项目打包以后的一个email测试类jar,放到linux上运行时报错: Error: A JNI error has occurred, please check your inst ...

  2. Spark资源调度分配内幕天机彻底解密:Driver在Cluster模式下的启动、两种不同的资源调度方式源码彻底解析、资源调度内幕总结

    本课主题 Master 资源调度的源码鉴赏 资源调度管理 任务调度与资源是通过 DAGScheduler.TaskScheduler.SchedulerBackend 等进行的作业调度 资源调度是指应 ...

  3. [转]Android开源项目收藏分享

    转自:http://blog.csdn.net/dianyueneo/article/details/40683285 Android开源项目分类汇总 如果你也对开源实现库的实现原理感兴趣,欢迎 St ...

  4. NO.012-2018.02.17《题都城南庄》唐代:崔护

    题都城南庄_古诗文网 题都城南庄 唐代:崔护 去年今日此门中,人面桃花相映红.去年春天,就在这扇门里,姑娘脸庞,相映鲜艳桃花.人面:指姑娘的脸.第三句中“人面”指代姑娘. 人面不知何处去,桃花依旧笑春 ...

  5. char *转string遇到诡异的问题记录

    这个问题的背景是在用libevent的buffer_remove时出现的,写一个伪代码 char buffer[2048] ={0}; string str; int n = buffer_remov ...

  6. ADF系列-2.EO的高级属性

    在上一篇博客 ADF系列-1.EO的各个属性初探 中介绍了EO的一些常用简单属性.本次将介绍EO中一些比较常用的一些高级属性 一.基于Sequence创建EO,一下介绍三种方式(以HR用户的Emplo ...

  7. sql时间格式转换

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...

  8. yolo2 anchor选择校招总结

    使用kmeans的聚类算法选择数据集最可能的anchor size和ratio.K-means算法是很典型的基于距离的聚类算法,采用距离作为相似性的评价指标,即认为两个对象的距离越近,其相似度就越大. ...

  9. Git--将服务器代码更新到本地

    1. git status(查看本地分支文件信息,确保更新时不产生冲突) 2. git checkout -- [file name] (若文件有修改,可以还原到最初状态; 若文件需要更新到服务器上, ...

  10. bit and sbit---c51

    bit和sbit都是C51扩展的变量类型. bit和int char之类的差不多,只不过char=8位, bit=1位而已.都是变量,编译器在编译过程中分配地址.除非你指定,否则这个地址是随机的.这个 ...