C++中map的简单使用
2017-05-16 11:01
337 查看
话不多说,直接上代码,Y宝宝手把手教的我很开心呢!
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string,int>mp;
map<string,int> :: iterator it;
int n;
string str;
while(cin>>n)
{
mp.clear();
string k;
int maxn=-999;
for(int i=0;i<n;i++)
{
cin>>str;
mp[str]++;
if(mp[str]>maxn)
{
maxn=mp[str];
k=str;
}
}
/*
for(it=mp.begin() ;it!=mp.end();it++)
{
if(it->second>maxn)
{
maxn=it->second;
k=it->first;
}
}*/
cout<<k<<endl;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string,int>mp;
map<string,int> :: iterator it;
int n;
string str;
while(cin>>n)
{
mp.clear();
string k;
int maxn=-999;
for(int i=0;i<n;i++)
{
cin>>str;
mp[str]++;
if(mp[str]>maxn)
{
maxn=mp[str];
k=str;
}
}
/*
for(it=mp.begin() ;it!=mp.end();it++)
{
if(it->second>maxn)
{
maxn=it->second;
k=it->first;
}
}*/
cout<<k<<endl;
}
return 0;
}
相关文章推荐
- C++中Map的使用 (个人简单的对于String的使用)
- C++ 中map 中迭代器的简单使用:
- c++ map简单使用
- STL 之 C++ Map容器的简单使用方法
- C++map和set的简单理解和使用案例
- (转载自老骆驼)C++中的vector简单使用范例
- Google Map Api 简单使用笔记
- Visual C++ Profile的简单使用方法
- throw()使用小结:More effective C++:审慎使用异常规格(转),简单举例
- [超简单]C++如何使用MySQL数据库
- 一起学windows phone7开发(二十一.二 Map控件的简单使用)
- LINUX下简单的编译和使用动态链接库[compile .so use c++ in linux]
- [C++][MFC]CFile的一些简单使用
- c++ map的使用--键值对的集合
- C++循环的简单使用【闲来写来练练手~】
- 词频统计的C++实现(使用stl--map)
- 在遍历C++map中删除元素算法(简单例子)
- 使用C++对文件加密的简单例子
- Linux下,使用C/C++编写一个简单的消息处理程序
- Carbide.c++简单使用之import and debug SDK example