题解 | #单词识别#

单词识别

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

#include<iostream>
using namespace std;
#include<vector>
#include<map>
#include<algorithm>
int main()
{
    string str;
    getline(cin,str);
    string temp;
    vector<string> num;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]!=' ' && str[i]!='.')
        {
            temp+=tolower(str[i]);
        }
        else{
            num.push_back(temp);
            temp.clear();
        }
    }
    //以上就是将字符串进行分割
    map<string,int> count;
    for(auto ch: num)
    {
        count[ch]++;    
    }
    map<string,int>::iterator it=count.begin();
    while(it!=count.end()){
        cout << it->first <<":"<<  it->second << endl;
        it++;
    }
}

全部评论

相关推荐

07-09 15:55
门头沟学院 Java
点赞 评论 收藏
分享
昨天 13:16
湖南工学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

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