C++ 用到了unordered_map、pair、sort lambda表达式
#include <algorithm> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { unordered_map<string, int> keywords; string word; while (cin >> word) { keywords[word]++; } vector<pair<string, int>> words(keywords.begin(), keywords.end()); sort(words.begin(), words.end(), [](const auto &a, const auto &b) { return a.second==b.second ? a.first<b.first : a.second>b.second; }); for (auto i : words) { if (i.second<3) break; cout << i.first << endl; } } // 64 位输出请用 printf("%lld")