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 ...
随机推荐
- Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application
http://www.codeproject.com/Articles/1003177/Access-bit-HKLM-Software-Registry-by-bit-Csharp-NE While ...
- Java虚拟机1:开篇
1.前言 由于后期学习需要用到大量的JVM底层的东西,所有本人调整了一下学习计划,打算先从JVM入手,了解整个JAVA的运行机制,内存模型,编译原理等等一些底层的东西,这样在学习 后面的东西,会有一种 ...
- BZOJ3503:[CQOI2014]和谐矩阵(高斯消元,bitset)
Description 我们称一个由0和1组成的矩阵是和谐的,当且仅当每个元素都有偶数个相邻的1.一个元素相邻的元素包括它本 身,及他上下左右的4个元素(如果存在). 给定矩阵的行数和列数,请计算并输 ...
- ServletRequest的四个主要方法
package com.yunqing.servlet; import javax.servlet.*; import java.io.IOException; import java.util.Ar ...
- Intellij IDEA如何删除项目
1. 删除某个项目 1) 选中项目,并关闭 2) File-Open,再选中相应的项目,并delete即可,它会同时在硬盘上删除
- idea中查看类层级class hierarchy
idea中,我当前设置的是eclipse的快捷键(从eclipse转过来的) 一般情况下,查看类的子类Ctrl+T 如何以树的形式查看完整继承关系,快捷键:F4 效果如下: 尤其从根节点查看的时候,完 ...
- 对IIS7经典模式和集成模式的理解(转载)
从IIS6新增应用程序池的概念,到现在IIS7,对HTTP请求处理功能已经越来越精确化和不断改善,IIS7应用程序池新增了经典模式和集成模式可供选择,不管官方还是一些书籍或文章都有介绍,但多数过于官方 ...
- I/O复用——各种不同的IO模型
一.概述 我们看到上面的TCP客户同时处理两个输入:标准输入和TCP套接字.我们遇到的问题就是在客户阻塞于(标准输入上的)fgets调用期间,服务器进程会被杀死.服务器TCP虽然正确地给客户TCP发送 ...
- 过滤器Filter在配置文件中不起作用
web.xml内容 <filter> <filter-name>LoginFilter</filter-name> <filter-class>com. ...
- 安装sqlserver2016出现的错误
今天安装sharepoint 2016,projectserver 2016,在安装sqlserver2016的时候突然报错了,提示需要安装oracle java se, Rule “Oracle J ...