ACM1004:Let the Balloon Rise
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
/*
简单题,统计气球数最多的颜色
*/
#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的更多相关文章
- 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 ...
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- Let the Balloon Rise(水)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- 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 ...
- 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 ...
随机推荐
- 如何访问tomcat所在服务器的其他盘符的资源。
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWA ...
- 20、Springboot 与数据访问(JDBC/自动配置)
简介: 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合 Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入 各种xxxTemplate,x ...
- 关闭 XXXXX 前你必须关闭所有会话框
这个问题应该是和Microsoft管理控制台(Microsoft Management Console,MMC)有关系 我是在使用 任务计划程序 时碰到这个问题的,网上也有其他人在使用 事件查看器 的 ...
- 说说application/x-www-form-urlencoded和application/json的区别
今天一位同事在于微信小程序开发人员那边在对接测试的时候,遇到了一个错误,安卓那边是以application/json作为请求体类型,而Java这边仍向往常那样没有多么大的变化,但是就是前台传输的数据为 ...
- 用@ExceptionHandler 来进行异常处理
有时候我们想统一处理一个Controller中抛出的异常怎么搞呢? 直接在Controller里面加上用@ExceptionHandler标注一个处理异常的方法像下面这样子 @ExceptionHan ...
- 使用Fiddler做抓包分析
转载:http://blog.csdn.net/ohmygirl/article/details/17849983 Fiddler抓取HTTP请求. 抓包是Fiddler的最基本的应用,以本博客为例, ...
- Classless Interdomain Routing (CIDR)
IP Address Problems IP Address Exhaustion Class A, B, and C address structure inefficient Class B to ...
- CSS3与页面布局学习总结(四)——页面布局的多种方法
一.负边距与浮动布局 1.1.负边距 所谓的负边距就是margin取负值的情况,如margin:-100px,margin:-100%.当一个元素与另一个元素margin取负值时将拉近距离.常见的 ...
- Many-to-many relationships in EF Core 2.0 – Part 3: Hiding as ICollection
In the previous post we ended up with entities that hide the join entity from the public surface. Ho ...
- 一点一点看JDK源码(二)java.util.List
一点一点看JDK源码(二)java.util.List liuyuhang原创,未经允许进制转载 本文举例使用的是JDK8的API 目录:一点一点看JDK源码(〇) 1.综述 List译为表,一览表, ...