11-散列1-电话聊天狂人-编程题 解题代码测试结果问题整理 解题代码 #include<iostream> #include<map> #include<string> using namespace std; map<string, int> m; int main() { string a, b; int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a >> b; m[a]++; m[b]++; } int max=0; string maxstr; for (auto it : m) { if (it.second > max) { max = it.second; maxstr = it.first; } } int cnt=0; for (auto it : m) if (it.second == max) cnt++; if (cnt == 1) cout << maxstr << " " << max; else cout << maxstr << " " << max << " " << cnt; return 0; } 测试结果 问题整理 1.本想最后利用count来计算个数,但m.count(key)只返回主键值的出现次数,然而只能是1或者0,不能计算value出现的次数。