题解 | #单词识别#
单词识别
https://www.nowcoder.com/practice/16f59b169d904f8898d70d81d4a140a0
#include <cctype>
#include <iostream>
#include <string>
#include <ctype.h>
#include <map>
using namespace std;
string& tranform(string& word)
{
for(auto& e : word)
{
if(isupper(e)) e = tolower(e);
if(e == '.') word.pop_back();
}
return word;
}
int main()
{
string word;
map<string, int> countMap;
while(cin >> word)
{
// 单词入map之前需要处理句号和单词转小写
countMap[tranform(word)]++;
}
for(auto& e : countMap)
{
cout << e.first << ":" << e.second << endl;
}
return 0;
}
查看16道真题和解析