题解 | #单词识别#

单词识别

https://www.nowcoder.com/practice/16f59b169d904f8898d70d81d4a140a0

#include <iostream>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

//堆
// struct Compare
// {
//     bool operator()(const pair<string,int>& p1,const pair<string,int>& p2)
//     {
//         if(p1.second != p2.second)
//         {
//             return p1.second < p2.second;
//         }
//         else
//         {
//             return p1.first > p2.first;
//         }
//     }
// };
// int main() {
//   string s;

//     unordered_map<string,int> umap;

//     while(getline(cin,s))
//     {
//         string temp;
//        for(int i = 0; i < s.size(); i++)
//        {
//         if(s[i] == ' ' || s[i] == '.')
//         {
//             if(temp != "")
//                 umap[temp]++;
//             temp = "";
//         }
//         else
//         {
//             temp+=tolower(s[i]);
//         }
//        }
//     }

//     priority_queue<pair<string,int>,vector<pair<string,int>>,Compare> pq;

//     for(auto& e : umap)
//     {
//         pq.push(e);
//     }

//     while(!pq.empty())
//     {
//         auto e = pq.top();
//         cout << e.first << ":" << e.second << endl;
//         pq.pop();
//     }
    

// }

//sort
struct Compare
{
    bool operator()(const pair<string,int>& p1,const pair<string,int>& p2)
    {
       return p1.second > p2.second;
    }
};
int main() {
  string s;

    map<string,int> map;

    while(getline(cin,s))
    {
        string temp;
       for(int i = 0; i < s.size(); i++)
       {
        if(s[i] == ' ' || s[i] == '.')
        {
            if(temp != "")
                map[temp]++;
            temp = "";
        }
        else
        {
            temp+=tolower(s[i]);
        }
       }
    }

    vector<pair<string,int>> v(map.begin(),map.end());
    sort(v.begin(),v.end(),Compare());

    for(auto& e : v)
    {
        cout << e.first << ":" << e.second << endl;
    }

    

}

全部评论

相关推荐

投递京东等公司10个岗位
点赞 评论 收藏
分享
搜索部&nbsp;首先说下timeline8.18,投递8.19,约一面8.21,晚上一面call约二面8.22,上午二面下午oc周末等待(8.23,8.24)8.25,offer一年前,我还是懵懵懂懂,高考完的暑假,只会提前学学高数,未来的画像是什么?我或许无法预测。开学后,自学Python,接单,无数个客户的ddl,偷偷摸摸一个人找自习的地方,这一步步竟然为后来的我,搭建工程能力的基础。大一上,我也要感谢我的第一位老板,让我接触到了实习,师兄带着我一步步入门,看他们写的飞书文档。大一下,导师带我参与企业项目,这让我渐渐发现,应该去实践,增长见识,而非局限当下,盯着自己的小新pro。不久后,第一波投递开始,结果当然是约面极少。盯着简历上的文字和ssob,我开始思考,确实很多可以去提升。带着些许不甘心,继续沉淀,慢慢的约面也越来越多,有的时候两天7场,准备完就接着下一个日程。这一次,也许是刚好到位吧,比较match,面试答的流利,关关难关关过,成为度孝子展望未来,依然是重重挑战,果然只有收到offer的那一刻是开心的。愿在百度星海拆解的每一段代码,都能成为丈量宇宙的诗行;此志终赴星河,而今迈步重铸天阶。屏幕前的你们,在无数个向星海奔赴的日夜,一定一定,会在未来化作群星回响的征程——请永远相信此刻埋首耕耘的自己!!!
一天三顿半:???百度提前批发 offer了?不是统一和正式批排序完再发吗我靠
百度求职进展汇总
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务