题解 | #单词识别#
单词识别
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; }
题目错了吧, 我按字典序升序也可以过~