基本思想:
存在问题,无论用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