小红书有一个推荐系统,可以根据用户搜索的关键词推荐用户希望获取的内容。现在给定小红的搜索记录(记录为分词后的结果),我们认为当一个单词出现的次数不少于3次时,该单词为“用户期望搜索的单词”,即称为关键词。请你根据小红的记录,输出小红的用户画像对应的所有关键词。时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 256M,其他语言512M输入描述:一行字符串,仅由小写字母和空格组成。代表小红的搜索记录。字符串长度不超过100000。输出描述:小红所有的关键词。每行输入一个。你需要按照搜索频次从高到低输出。频次相同的,你需要按字典序升序输出。示例1输入例子:kou red game red ok who game red karaoke yukari kou red red nani kou can koukou ongakugame game输出例子:redgamekou#include <iostream>#include<algorithm>#include<vector>#include<map>using namespace std;struct mapcomparator {    bool operator()(const std::pair<string, int>& a, const std::pair<string, int>& b) {        if (a.second == b.second) {            return a.first < b.first;        }        return a.second > b.second;    }};int main() {    string a;    map<string, int> wmap;    while (cin >> a) { // 注意 while 处理多个 case        wmap[a] ++;    }    vector<std::pair<string,int>> sortMap(wmap.begin(), wmap.end());    std::sort(sortMap.begin(), sortMap.end(), mapcomparator());    auto it = sortMap.begin();    while(it!=sortMap.end()){        if(it->second > 2){            cout<< it->first <<endl;        }        it++;    }}// 64 位输出请用 printf("%lld")
点赞 2
评论 0
全部评论

相关推荐

04-25 19:29
已编辑
宁波大学 运营
被普调的六边形战士很高大:你我美牛孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务