HDU 1004(map的使用)

传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1004

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 143275    Accepted Submission(s): 56670

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

Author

WU, Jiazhi

题目意思:

找颜色单词出现得最多的那个单词

分析:

map的用法

很方便呀

原来都没有怎么用过

第一次用

开心

好用

code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n)
    {
        map<string,int> mm;
        map <string,int>::iterator it;
        string ch;
        for(int i=0;i<n;i++)
        {
            cin>>ch;
            mm[ch]++;
        }
        int sum=0;
        string str;
        for(it=mm.begin();it!=mm.end();it++)
        {
           if(it->second>sum)
           {
               sum=it->second;
               str=it->first;
           }
        }
        cout<<str<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/yinbiao/p/9295827.html

时间: 2024-10-05 00:07:45

HDU 1004(map的使用)的相关文章

hdu 1004 map和非map写法

Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 116867 Accepted Submission(s): 45783 Problem Description Contest time again! How excited it is to see balloons floating around.

HDU 1004 MAP【STL__map_的应用】

强大的MAP,今天终于开始好好学习一次. map内部是用红黑树维持的有序结构. 定义:map<int,string>mapStudent; 查找的时间复杂度为对数级别. 1.构造方法学习两种: 第一种:用insert函数插入pair数据,mapStudent.insert(pair<int, string>(0,"jiangjing")); 第二种:用数组方式插入数据 mapStudent[1] = "jiangjing1";  mapStu

HDU 1004

第一次写map 纪念 1 #include <map> 2 #include <cstdio> 3 #include <iostream> 4 #include <string> 5 #include <cstring> 6 #include <string.h> 7 using namespace std; 8 map<string,int> a; 9 int main(){ 10 int t,max1; 11 stri

hdu 1247 map的使用

http://acm.hdu.edu.cn/showproblem.php?pid=1247 Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7760    Accepted Submission(s): 2814 Problem Description A hat’s word is a word in the

hdu 4941 map的应用+离散

1 #include<iostream> 2 #include<cstdio> 3 #include<map> 4 #include<algorithm> 5 using namespace std; 6 7 int main() 8 { 9 int T,n,m,k,a,b,c,q,cas=1; 10 scanf("%d",&T); 11 while(T--) 12 { 13 map<int,map<int,int&g

HDU 4287 &lt;map&gt;的使用

对于这道题我主要要讲得是STL中map的简单使用. 先说说map的用处. map就是从键(key)到值(value)的映射.因为重载了[]运算符,map像数组的"高级版",例如可以用一个map<string,int>month_name来表示"月份名字到月份编号"的映射,然后用month_name["July"] = 7这样的方式来赋值. 它的意思就是map<string,int>month_name表示[ ] 里面代表的

HDU 4921 Map DFS+状态压缩+乘法计数

算最多十条链,能截取某前缀段,每种方案都可以算出一个权值,每种方案的概率都是总数分之一,问最后能构成的所有可能方案数. 对计数原理不太敏感,知道是DFS先把链求出来,但是想怎么统计方案的时候想了好久,其实因为只能取某个链的前缀,所以直接取链长加+1 然后相乘即可,当然因为会出现都是空的那种情况,要去掉,全部乘完之后,要-1 然后就是算权值了,权值等于当前加进来的点的总和 以及 等级相同的点的加成,并不是特别好算,这时候考虑每个状态下的点对全局的贡献,对,就是这个思想,用状态压缩来表示状态,然后这

HDU 1075 map or 字典树

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 12773    Accepted Submission(s): 4069 Problem Description Ignatius is so lucky that he met a Martian yesterday. But

HDU 4921 Map

题意: 给n个节点  他们形成了最多10条链  每条最多1000的长度  每个节点有个val  你可以选择任意位置截断链  断点前的所有节点被你获得  通过题中计算公式得出你的val  问  通过随机截断  获得val的期望是多少 思路: 期望=所有方案val的和/方案数 这里明显有分层的现象  而且每层最多10个元素  因此想到状压  那么我们只要逐层统计  每层计算一下能对"所有方案val的和"产生多少贡献即可  方案数可以直接算出来  计算方法如下 对于方案数  它就等于 (am

HDU 1004 Let the Balloon Rise【STL&lt;map&gt;】

Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 123800    Accepted Submission(s): 48826 Problem Description Contest time again! How excited it is to see balloons floating ar