2018学校暑期集训第一天——C++与STL

练习题B ——  HDU - 1004

B - 双对福音的协议

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

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;int main(void)
{int n;while (~scanf("%d", &n) && n != 0) {map<string, int> color;string co;for (int i = 0; i < n; i++) {cin >> co;color[co]++;}int j = 0;map<string, int>::iterator it;for (it = color.begin(); it != color.end(); it++)if ((it->second) > j)j = it->second;for (it = color.begin(); it != color.end(); it++)if ((it->second) == j)cout << it->first << endl;}return 0;
}

暑期集训1:C++STL 练习题B:HDU-1004相关推荐

  1. 暑期集训1:C++STL 练习题D:HDU-1509

    2018学校暑期集训第一天--C++与STL 练习题D --  HDU - 1509 D - 振电迁移的日蚀 Message queue is the basic fundamental of win ...

  2. 暑期集训1:C++STL 练习题C:HDU-1263

    2018学校暑期集训第一天--C++与STL 练习题C --   HDU - 1263 C - 亡失流转的孤独 夏天来了~~好开心啊,呵呵,好多好多水果~~  Joe经营着一个不大的水果店.他认为生存 ...

  3. 暑期集训1:C++STL 练习题E:POJ-2431

    2018学校暑期集训第一天--C++与STL 练习题E --  POJ - 2431 E - 二律背反的对偶 A group of cows grabbed a truck and ventured ...

  4. 暑期集训1:C++STL 练习题A:POJ-1833

    2018学校暑期集训第一天--C++与STL 练习题A -- POJ-1833 A - 闭时曲线的引言 Time Limit: 1000MS   Memory Limit: 30000K Total ...

  5. 暑期集训1:C++STL 例1:UVA-10815

    2018学校暑期集训第一天--C++与STL 例一  --  UVA - 10815 Andy's First Dictionary Description XY学长刚刚立下了再不过CET就直播xx的 ...

  6. 暑期集训1:C++STL 例3:UVA-12100

    2018学校暑期集训第一天--C++与STL 例三  --  UVA - 12100 Printer Queue The only printer in the computer science st ...

  7. 暑期集训1:C++STL 例2:UVA-10935

    2018学校暑期集训第一天--C++与STL 例二  --  UVA - 10935 Throwing cards away I Given is an ordered deck of n cards ...

  8. 题解报告(CDUT暑期集训——第二场)

    题解报告(CDUT暑期集训--第二场) D - Game HDU - 6312 思路:水题 Alice一直是必胜态 AC代码 #include<stdio.h> #include<i ...

  9. 暑期集训5:并查集 线段树 练习题G: HDU - 1754

    2018学校暑期集训第五天--并查集 线段树 练习题G  --   HDU - 1754 I Hate It 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让 ...

最新文章

  1. 华为 | 人生苦短,码短情长,有场大Party等你来Pick!
  2. 人类将可能操控AI?神经网络语言处理工作原理被破解
  3. freemarker写入word【未完,待续】
  4. 完美搞定《DOCKER IN ACTION》第二章示例
  5. intellij 快捷键整理
  6. arthas 查看哪个方法调用最耗时_Java开源诊断工具Arthas使用方法详解
  7. java 判断对象为控制_Java流程控制
  8. python购物车_python购物车功能
  9. 父子/父孙传参(Provide/inject方式)
  10. 字体系列之字体复合属性(CSS、HTML)
  11. python_jpype1 调用java代码
  12. 锐捷服务器虚拟化技术_锐捷核心交换机VSU虚拟化配置
  13. 小管家进销存_管家婆物联宝微订货V2.3发版公告
  14. javascript实现繁体简体转换
  15. python 根据x的值和函数y=20+x2,计算y_new,算出y_new和y的差,记为delta_y。¶绘制x和delt_y的点图,并计算y的方差。有关方差的计算参阅数学资料。
  16. Java中存储金额用什么数据类型?
  17. 英语表达的收集类游戏
  18. linux下双网卡绑定,Linux下双网卡绑定bond0
  19. python pygame 游戏实践: 俄罗斯方块(Tetris Game)第一步
  20. mysql dba工具_Github推荐:MySQL DBA不可错过的五大开源管理工具!

热门文章

  1. 联想打字必须按FN+数字-fn打字
  2. 艾伟也谈项目管理,敏捷教练的工具箱
  3. 织梦html引入html代码,织梦标签引入共html.doc
  4. javascript_JavaScript疲劳疲劳
  5. phpinfo 信息利用
  6. 当前路径_[JSP] 07 JSP 路径问题
  7. JAVA动态读取xml_Java动态生成和解析xml文件步骤详解
  8. (C++)用指针实现两数交换函数swap()的两种方法
  9. 【Python培训基础知识】Python生成器函数
  10. c语言初学 循环 的灵活使用小案例