关于map的一个习题,忽略大小写和标点符号单词的计数器
发布日期:2021-05-07 00:55:45 浏览次数:27 分类:精选文章

本文共 585 字,大约阅读时间需要 1 分钟。

 c++ primer5th,map的一个习题 11.4

#include 
#include
#include
#include
#include
using namespace std;void to_lower(string &s);int main(){map
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());}

 

上一篇:c++关联容器的容器操作(和顺序容器都支持的操作)详细解释,基础于c++primer 5th 表 9.2 (持续更新)
下一篇:Ubuntu20.04安裝QQ for Linux

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月09日 18时03分56秒