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<string, int>, 通过cnt["string"]=int的方法储存值,学习其中关于“找a是否存在,不存在就先让它为0,再加1,存在就直接加一”

代码如下

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<stdlib.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 100;
double eps = 1e-8;
map<string, int> cnt;
int main(){
int n;
while(scanf("%d", &n) && n){
cnt.clear();
string a;
int ans =0;
string anss;
for(int i = 0; i < n ; i++){
cin >> a;
if(!cnt.count(a))cnt[a]=0;
cnt[a]++;
if(cnt[a]>ans){
ans =cnt[a];
anss = a;
}
}
cout << anss << endl; } return 0;
}

最新文章

  1. JSON-fastjson
  2. jQuery的$.getJSON方法在IE浏览器下失效的解决方案
  3. 在Windows 10下启用旧的照片查看器
  4. Java图形化用户界面(GUI)笔记(一)介绍
  5. hdu2108(判断凸多边形)
  6. SQL Server Data Tool 嘹解(了解)一下 SSDT -摘自网络
  7. Maven的生命周期
  8. macOS apache配置及开启虚拟服务器的开启,apache开启重写模式
  9. Java前后端依赖
  10. [转帖]linux tree命令--显示目录的树形结构
  11. C:malloc/calloc/realloc/alloca内存分配函数
  12. python与中文的那点事
  13. Angular 实现Bootstrap ScrollSpy控件
  14. 从零系列--开发npm包(一)
  15. Asynchronous and non-Blocking I/O 翻译[收藏好文]
  16. Jsonp的实现
  17. 通过命令更新git for windows
  18. Linux内核中内存cache的实现【转】
  19. xp远程桌面连接最大用户数怎么设置?
  20. ubuntu安装出现&quot;删除initramfs-tools时出错&quot;,subprocess installed post-installation script returned error exit status 1

热门文章

  1. Java读取数据库中的xml格式内容,解析后修改属性节点内容并写回数据库
  2. express框架中使用nodemon自启动服务
  3. kuangbin专题 专题九 连通图 Strongly connected HDU - 4635
  4. 《C# 爬虫 破境之道》:第一境 爬虫原理 — 第一节:整体思路
  5. 如何选择kmeans中的k值——肘部法则–Elbow Method和轮廓系数–Silhouette Coefficient
  6. 异数OS TCP协议栈测试(四)--网卡适配篇
  7. HttpApplication IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable ps url System.Web.dll
  8. Dynamics 365 CRM 在 Connected Field Service 中部署 IoT Central (二)- 匹配设备
  9. selenium获取页面源码,判断是否存在指定内容,执行不同的操作
  10. iperf安装使用教程