C++//练习11.4扩展你的程序,忽略大小写和标点。例如,“example.“、“exmaple,“和”Exa
- 人工智能
- 2025-07-22 02:12:01
C++ Primer(第5版) 练习 11.4
练习 11.4 扩展你的程序,忽略大小写和标点。例如,“example.”、"exmaple,"和”Example"应该递增相同的计数器。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块 /************************************************************************* > File Name: ex11.4.cpp > Author: > Mail: > Created Time: Tue 02 Apr 2024 09:42:21 AM CST ************************************************************************/ #include<iostream> #include<iomanip> #include<cctype> #include<string> #include<map> #include<set> #include<vector> #include<algorithm> using namespace std; int main(){ map<string, size_t> wordCount; set<string> unique = {".", ","}; string word; cout<<"Enter words: "; while(cin>>word){ transform(word.begin(), word.end(), word.begin(), ::tolower); if(ispunct(word[word.size()-1])){ word.erase(word.size()-1); } ++wordCount[word]; if(cin.get() == '\n'){ break; } } cout<<"Word Count: "<<endl; for(const auto &w : wordCount){ cout<<"Word: "<<setw(8)<<left<<w.first<<" Count: "<<w.second<<endl; } return 0; } 运行结果显示如下
C++//练习11.4扩展你的程序,忽略大小写和标点。例如,“example.“、“exmaple,“和”Exa由讯客互联人工智能栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“C++//练习11.4扩展你的程序,忽略大小写和标点。例如,“example.“、“exmaple,“和”Exa”
上一篇
AndroidFence机制
下一篇
云计算面临的威胁