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 ...
随机推荐
- MyEcplise使用---使用 MyEclipse 反转引擎生成数据库
使用 MyEclipse 反转引擎,生成数据库 步骤: 1. 新建 Database 连接 2. 新建web项目 temp 添加myeclipse hibernate 能力 3. Hibernate ...
- IERS-OSPF基本工作原理
IERS-OSPF基本工作原理 一.邻居建立建立过程 1.Router ID 用于在自治系统中唯一标识一台运行OSPF的路由器,每台运行OSPF的路由器都有一个ROUTER ID Route ID 是 ...
- 实验5&期中考试后两题
实验内容1: #include <iostream> #include <vector> #include <string> using namespace std ...
- Future Research Directions in Social Recommendation
From the tutorial published by Martin Ester in RecSys 2013 Future Research Directions --Recommendati ...
- codeforces 814E An unavoidable detour for home
题目链接 正解:$dp$. 感觉这道题就是中国象棋的加强版..我们要发现一些性质. 首先就是这个图肯定是一个按照$bfs$序分层的图,且每个点只往自己上面那一层连了一条边,每个点不可能向自己的上面超过 ...
- 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...
- mybatis全局配置文件
一.properties:引入外部配置文件 1.resource :引入类路径下的全局配置文件,例如:<properties resource="conf/dbconfig.prope ...
- UglifyJS 压缩选项
UglifyJS 压缩选项 1.使用逗号运算符连接简单语句 2.使用点符号代替中括号属性 foo [“bar”]→foo.bar 3.删除逻辑上走不到的代码 4.删除调试代码 debug ...
- JavaScript在浏览器中把文本保存为文件的方法
JavaScript在浏览器中把文本保存为文件的方法 经过测试第二种方法可以保存更多的文本不至于卡死 var saveTextAsFile1 = function (text, fileName, s ...
- MyBatis之Mapper XML 文件详解(二)-sql和入参
sql 这个元素可以被用来定义可重用的 SQL 代码段,可以包含在其他语句中.它可以被静态地(在加载参数) 参数化. 不同的属性值通过包含的实例变化. 比如: <sql id="use ...