#include <stdio.h>
#include <string.h>
char a[][];
int b[]={};
int main()
{
int n,i,j,k,max,loc;
while(scanf("%d",&n)!=EOF&&n!=){
max=-;
k=;
loc=;
for(i=;i<n;i++){
scanf("%s",a[k]);
for(j=;j<k;j++){
if(strcmp(a[j],a[k])==){
b[j]++;
k--;
break;
}
}
k++;
}
for(i=;i<k;i++){
if(b[i]>max){
max=b[i];
loc=i;
}
b[i]=;
}
puts(a[loc]);
}
return ;
}

gets遇到回车才结束,并把回车符改为'\0'再存到字符串。注:如果输入的数字过长,这个函数会出问题,因为他不判断输入的长度的。

puts只要遇到第一个'\0'就会输出,并自动输出一个换行符。

格式:这个格式没很大问题,遇到0就结束,而不用输出换行再结束。

思路:

1、题中明确说答案只会有一个,也就是不会出现比如:2 red green的情况。

2、一个二维的字符数组,保存输入的颜色。

3、一个int型数组记录每个颜色出现的次数。(我把他初始化为0,是因为次数不重要,重要的是谁是最多的,实际上应该是该数字+1)

技巧:

1、每输入一个颜色,就对比前面输入的颜色中有没有出现过,若有,在该颜色位置对应的int数组上+1。

2、若输入的已经在之前的颜色中存在,在1中已经记录过出现的次数,那么颜色数组中刚输入的位置就可以重复利用了。

3、若输入的没有在之前的颜色中存在(即新颜色),该位置就不能被覆盖了。

4、输完之后,只需要对比一下int数组中的前k个就行啦(看代码),不用扫整个int数组了,这对于“大部分都是重复出现的颜色”情况就好多了,要是只有两个颜色,一次对比就搞定。

HDU 1004 Let the Balloon Rise(AC代码)的更多相关文章

  1. 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 ...

  2. HDU 1004 Let the Balloon Rise(map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  3. 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 ...

  4. hdu 1004 Let the Balloon Rise

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

  5. 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 ...

  6. 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 ...

  7. hdu 1004 Let the Balloon Rise 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...

  8. HDU 1004 Let the Balloon Rise(STL初体验之map)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. HDU 1004 - Let the Balloon Rise(map 用法样例)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. [转]何时使用委托而不使用接口(C# 编程指南)

    以下内容转自MSDN:http://msdn.microsoft.com/zh-cn/library/ms173173.aspx 委托和接口都允许类设计器分离类型声明和实现. 任何类或结构都能继承和实 ...

  2. JDE910笔记1--基础介绍及配置[转]

    1.一般JDE部署后环境: DV:开发环境 PY:测试环境 PD:正式环境 根据端口号区分不同环境,可配置.同时,JDE默认使用分发服务器,不同环境连接为不同的数据库. 2.命名规范: 自定义项目.函 ...

  3. 一个QMLListView的例子--

    一般人不知道怎么去过滤ListView里面的数据,下面是一个转载的文章:http://imaginativethinking.ca/use-qt-quicks-delegatemodelgroup/ ...

  4. Android设计画面中有EditText时取消启动时自动获得焦点调用系统输入法的方法

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  5. [ASP.NET] 使用Loading遮罩防止使用者重複點擊

    From: http://www.dotblogs.com.tw/joysdw12/archive/2012/12/13/85629.aspx 前言 在網頁執行中可能會因為資料量大或其他原因影響使用者 ...

  6. 戴文的Linux内核专题:06配置内核(2)

    转自Linux中国 这一部分我们讲配置内核IRQ子系统.中断请求(IRQ)是硬件发给处理器的一个信号,它暂时停止一个正在运行的程序并允许一个特殊的程序占用CPU运行. 这个目录中的第一个问题属于内核特 ...

  7. Program C--二分

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  8. Problem A CodeForces 560A

    Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses bankn ...

  9. [C/C++]C/C++相关网站

    1.http://en.cppreference.com What is the purpose of this site? Our goal is to provide programmers wi ...

  10. [pjsip]Pjlib中配置文件config.h解析

    config_site.h 这个头文件包含在config.h中,用于引入平台?(site)/用户特定的配置以控制PJLIB的特性,用户需要自己生成这个文件. 譬如说我们要把PJLIB编译成DLL,那么 ...