首页 > 其他 > 详细

map水题目

时间:2014-07-31 16:25:26      阅读:306      评论:0      收藏:0      [点我收藏+]

先做一个水题目。为了熟悉map的基本用法。记得在沈阳实训的时候,老师介绍过stl,里头的关联容器之一就是map,其实是是一个绑定索引,我觉得,蛮好用,除了new什么之类的不懂,其余删除,加入基本都会。

#include <iostream>
#include<map>
#include<string>
using namespace std;

map<string,int>ballon;
string a;
string maxs;
int t,maxi;
int main()
{
   while(cin >> t){
       ballon.clear();
       maxi = 0;
       if(!t)break;
       for(int i = 0;i < t;i++){
       cin >> a;
       ballon[a]++;
       }

       map<string,int>::iterator p;
       for(p = ballon.begin();p!=ballon.end();p++)
       {

           if(p->second > maxi)
           {

               maxi = p->second;
               maxs = p->first;
           }
       }
       cout << maxs << endl;
   }
   return 0;
}

 

map水题目,布布扣,bubuko.com

map水题目

原文:http://www.cnblogs.com/hhhhhhhhhhhhhhhhhhhhhhhhhhh/p/3880674.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!