题解 | #单词识别#

单词识别

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;
}

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

全部评论

相关推荐

Java面试先知:我也是和你一样的情况,hr 说等开奖就行了
点赞 评论 收藏
分享
notbeentak...:就抓,嗯抓,开不开匿名都要抓,一点坏事不让说,就对公司顶礼膜拜佩服的五体投地就对了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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