c++ associative container: map and set
来源:互联网 发布:二年级体测数据 编辑:程序博客网 时间:2024/06/01 10:36
#include <map>#include <set>#include <string>#include <iostream>#include <algorithm>#include <functional>#include <locale>void rightTrimPunct(std::string &str){ std::locale locl("C"); if (!str.empty()) { if (std::ispunct(str.back(), locl)) { str.pop_back(); } }}void toUpper(std::string &str){ std::locale locl("C"); std::transform(str.begin(), str.end(), str.begin(), std::bind(std::toupper<char>, std::placeholders::_1, locl));}int main(){ std::map<std::string, size_t> word_count; std::set<std::string> exclude = {"The", "But", "Or", "An", "A", "the", "but", "or", "an", "a"}; std::string word; while (std::cin >> word) { rightTrimPunct(word); toUpper(word); if (!word.empty() && exclude.find(word) == exclude.end()) ++word_count[word]; } for (const auto &w : word_count) { std::cout << w.first << " occurs " << w.second << ((w.second > 1) ? " times" : " time") << std::endl; } return 0;}
From C++ primer 5th Excercise 11.4 (p.422)
g++ *.cpp -std=c++11//gcc 4.9.2
0 0
- c++ associative container: map and set
- STL中的associative container hash map 红黑树 hash table
- 关联容器(Associative Container)
- 【primer 】chapter 10 Associative container
- Set, List And Map
- map and set
- Set-Associative Cache
- Set Associative Cache
- STL Associative Containers Types:map、set、multimap、mutilset以及对应的unordered类型
- 初学C++ associative container(关联容器)
- C++之关联容器(associative - container)简介
- Objective-c之Associative
- fully associative cache;set associative cache;direct mapped cache
- 数组 Arrays and associative arrays
- List, Set, Vector and Map in Java
- Differences among list,set and map
- Can you use map and set???
- Can you use map and set???
- uva 489
- C#中流程控制语句
- php生成 二维码
- NUPT大二队员淘汰赛1题解
- 基础练习 01字串
- c++ associative container: map and set
- apache虚拟主机
- Mac之Git/GitHub使用(4)——Be Social
- iOS 自定义TabBarController
- 设计模式之UML(一)类图以及类间关系(泛化 、实现、依赖、关联、聚合、组合)
- REST服务介绍
- jmx 监控 tomcat 和activemq
- 图形变换问题
- CQOI2008矩阵的个数