當前位置:
首頁 >
关于map的一个习题,忽略大小写和标点符号单词的计数器
發布時間:2024/4/18
35
豆豆
生活随笔
收集整理的這篇文章主要介紹了
关于map的一个习题,忽略大小写和标点符号单词的计数器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?c++ primer5th,map的一個習題 11.4
#include <iostream> #include <string> #include <map> #include <set> #include <cctype> using namespace std; void to_lower(string &s); int main() { map<string,unsigned> words_count; string str; while(cin >> str){to_lower(str);words_count[str] ++; } for(const auto & i : words_count) cout << i.first << " occurs " << i.second << (i.second > 1?"time":"times") << endl;return 0; }void to_lower(string &s) { for(string::iterator it = s.begin();it != s.end();++ it){*it = tolower(*it);} char ch = *(--s.end()); if(ch == ',' || ch == '.' || ch == '!')s.erase(--s.end()); }?
總結
以上是生活随笔為你收集整理的关于map的一个习题,忽略大小写和标点符号单词的计数器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu20.04安裝QQ for
- 下一篇: c++关联容器的容器操作(和顺序容器都支