题解 | #单词识别#

单词识别

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

#include <iostream>
#include <map>
using namespace std;

map<string, int> hashmap; //按key 升序
int main(){
    string str;
    getline(cin, str);
    for(int i = 0; i < str.size(); i ++){
        if(isalpha(str[i])){
            int j = i;
            string r;
            while(isalpha(str[j]) && j < str.size()){
                r += tolower(str[j]);
                j ++;
            }
            i = j;
            hashmap[r] ++;
        }
    }
 
    for(auto i : hashmap){
        cout<<i.first<<":"<<i.second<<endl;
    }
    return 0;
}

题目错了吧, 我按字典序升序也可以过~

全部评论

相关推荐

10-09 19:08
已编辑
门头沟学院 Java
后端转测开第一人:换个模版 技术栈写的精炼紧凑一点 多投就行
点赞 评论 收藏
分享
10-20 16:50
门头沟学院 Java
强大的马里奥:考研报名还没结束,建议考个中游211,这样会好找一些
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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