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
 
 
此题我用了map   我做一些关于map的用法总结
map<string,int>::iterator j;
for (j=color.begin();j!=color.end();++j)
这个是遍历map的方法
map的初始化问题我还没找到解决的方法 于是此题讲其值直接改为零 找到方法之后我来更新
 
 //
// main.cpp
// hdu1004
//
// Created by tupeihui on 15/12/6.
// Copyright © 2015年 admin. All rights reserved.
// #include <iostream>
#include <map>
using namespace std;
map<string,int> color;
char s[];
int main() {
int n; while (scanf("%d",&n))
{
if (n==) break;
for (int i=;i<=n;i++)
{
scanf("%s",s);
color[s]+=;
}
map<string,int>::iterator j;
int ans=;
string anss;
for (j=color.begin();j!=color.end();++j)
{
if (j->second > ans)
{
ans=j->second;
anss=j->first;
}
color[j->first]=;
}
cout<<anss<<endl; }
return ;
}

hdu1004的更多相关文章

  1. HDU1004 (数组元素出现最多)

    HDU1004 思路:求数组中出现次数最多的那个元素: 遍历数组元素,找出每个元素出现的次数 Input Input contains multiple test cases. Each test c ...

  2. HDU1004之总是wa的细节问题

    #include <stdio.h> #include <string.h> int main() { ][]; int n, i, k, j, max, max_i; ){ ...

  3. HDU1004 BALLO0N

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

  4. HDU1004 查气球

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

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

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

  6. HDU1004题解分析(字符串处理)

    这道题是从上个星期开始做的,看到题时觉得似曾相似,好像做过,理了一下思路敲完代码又不对,后来发现是数组用错了,之后又重新想了数组和比较用法,昨天改了一个多小时,后来样例输出全部正确,所有情况都考虑到了 ...

  7. [HDU1004] Let the balloon rise - 让气球升起来

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

  8. 字符串处理-Hdu1004

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 题目大意:给你一个数n,要求输入n个字符串,在这n个字符串中,我们需要输出出现次数最多的字符串. ...

  9. HDU-1004.Let the ballon Rise(STL-map)

    2019-02-28-08:56:03 初次做本题是用字符串硬钢,最近校队训练时又遇到才知道用map是真的舒服.需要注意的是map的用法. clear : 清除map中的所有元素,map.clear( ...

随机推荐

  1. BADI

    BADI_MATERIAL_CHECK BOM_UPDATE MB_MIGO_BADI ME_GUI_PO_CUST ME_PROCESS_PO_CUST ME_REQ_POSTED WORKORDE ...

  2. sass1:

    less在处理CSS动画时,非常恶心,决定转向sass了.sass诞生得比less早,只是因为它是ruby写的,因此受众面够少.但我们不需要自己下编译器或使用命令行,我们可以koala这神器 首先几个 ...

  3. js localStorage 设置和取值

    定义 Storage 对象,对象有get(取值), set(设置), add(加入新值)三个方法 const Storage = {} Storage.get = function (name) { ...

  4. Java条件语句练习

    /*System.out.println("请输入三个数字:");//输入三个数字,返回最大的那个. int a,b,c,big; Scanner d = new Scanner( ...

  5. FPGA作为从机与STM32进行SPI协议通信---Verilog实现 [转]

    一.SPI协议简要介绍 SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用 ...

  6. 不安装HALCON下安装运行版U盘加密狗驱动

    参考halcon安装指导书 Installation Guide Depending on your operating system, you can install, configure, and ...

  7. vultr vps服务器存在的7个优势及选择原因

    原本准备在第一篇文章的时候完整的新注册账户的,但是考虑到对于这款VPS主机的了解,还是先整理这篇关于网络上和我自己在使用vultr vps主机产品的时候可能自认为的优势之处,这样可以加强很多新用户对于 ...

  8. 场景4 Data Warehouse Management 数据仓库

    场景4 Data Warehouse Management 数据仓库 parallel 4 100% —> 必须获得指定的4个并行度,如果获得的进程个数小于设置的并行度个数,则操作失败 para ...

  9. android 开发中fragment 遇到的问题

    http://yifeng.studio/2016/12/15/android-fragment-attentions/ 1.不要轻易在 fragment中引用 getactivity(); 解决方案 ...

  10. Python笔记-built-in函数,文件操作,lambda函数

    Built-In: i = abs(123) print(i) j = abs(-123) print(j)#123#123 #all,需要传一个可迭代的东西,里面所有的值是真,返回真 r1 = al ...