题解 | #单词识别#

单词识别

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

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

全部评论

相关推荐

牛客84809583...:举报了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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