hdu1004(map容器)
2016-04-17 09:25
363 查看
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
int n,maxnum;
string a,maxstr;
map<string, int> m;
int main()
{
while(cin >> n&&n){
m.clear();
for(int i =0; i < n; i++){
cin >> a;
m[a]++;
}
maxnum=0;
map<string, int>::iterator iter;
for(iter = m.begin();iter != m.end();iter++){
if(maxnum < iter->second){
maxnum=iter->second;
maxstr=iter->first;
}
}
cout <<maxstr<<endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
int n,maxnum;
string a,maxstr;
map<string, int> m;
int main()
{
while(cin >> n&&n){
m.clear();
for(int i =0; i < n; i++){
cin >> a;
m[a]++;
}
maxnum=0;
map<string, int>::iterator iter;
for(iter = m.begin();iter != m.end();iter++){
if(maxnum < iter->second){
maxnum=iter->second;
maxstr=iter->first;
}
}
cout <<maxstr<<endl;
}
return 0;
}
相关文章推荐
- jqGrid 学习笔记整理――进阶篇(一 )
- CF #347 (Div.2) C. International Olympiad(模拟)
- 23.JAVA编程思想——实用工具
- 22.JAVA编程思想——排序和搜索
- hdoj 1203 I NEED A OFFER!
- Swift中的iOS设计模式(二)
- 21.JAVA编程思想——未支持的操作
- 20.JAVA编程思想——实施解决方案
- HDU 5666 Segment(快速乘法/快速幂改)
- 《原创》网络版五子棋node.js+websocket
- 19.JAVA编程思想——使用Maps
- 18.JAVA编程思想——使用Sets
- C#——找出实现某个接口的所有类
- Swift中文教程(三) 字符串和字符
- pycharm快捷键及一些常用设置
- 17.JAVA编程思想——使用Lists
- ZOJ 3513 Human or Pig
- 16.JAVA编程思想——使用Collections
- 15.JAVA编程思想——新集合
- emgucv——findContours