首页 > 编程语言 > 详细

蓝桥杯 1558: [蓝桥杯][算法提高VIP]色盲的民主 Easy but have problems *map的用法

时间:2020-02-10 19:21:10      阅读:73      评论:0      收藏:0      [点我收藏+]

基本思想:

存在问题,无论用map还是数组排序,都有问题,感觉像是用例的问题;

 

关键点:

总结map的用法;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

map<string, int>m;


int main(){
    int n;
    cin >> n;
    string s;
    getchar();
    int max = 0;
    for (int i = 0; i < n; i++) {
        getline(cin, s);
        if (m.find(s) == m.end()) {
            m.insert(make_pair(s,1));
        }
        else {
            m[s]++;
            if (m[s] > max)
                max = m[s];
        }
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second == max)
            cout << it->first << endl;
    }
    return 0;
}

 

蓝桥杯 1558: [蓝桥杯][算法提高VIP]色盲的民主 Easy but have problems *map的用法

原文:https://www.cnblogs.com/songlinxuan/p/12291901.html

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