题解 | 小红书推荐系统
小红书推荐系统
https://www.nowcoder.com/practice/e5b39c9034a84bf2a5e026b2b9b973d0
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
unordered_map<string, int> dict;
string word;
while(cin >> word) {
dict[word]++;
}
using mapPtr = unordered_map<string, int>::iterator;
vector<mapPtr> keywords;
for(auto it = dict.begin(); it != dict.end(); ++it) {
if (it->second >= 3)
keywords.push_back(it);
}
sort(keywords.begin(), keywords.end(), [](const mapPtr a, const mapPtr b) {
if (a->second != b->second)
return a->second > b->second;
else
return a->first < b->first;
});
for(const auto it: keywords) {
cout << it->first << endl;
}
}
// 64 位输出请用 printf("%lld")
每日一题@牛客网 文章被收录于专栏
牛客网每日一题
查看11道真题和解析