11.4 编写单词计数程序,忽略大小写和标点。例如,“example.”,“example,"和”Example“应该递增相同的计算器。

#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std; int main()
{
map<string,size_t> word_count;
string word;
while(cin>>word)
{
word[]=tolower(word[]);
auto f=find(word.begin(),word.end(),',');
if(f!=word.end())
word.erase(f);
auto ff=find(word.begin(),word.end(),'.');
if(ff!=word.end())
word.erase(ff);
++word_count[word];
}
for(auto w:word_count)
cout<<w.first<<" occurs "<<w.second<<endl;
return ;
}

11.7定义一个map,关键字是家庭的姓,值是一个vector,保存家中孩子们的名。编写代码,实现添加新的家庭以及向已有家庭中添加新的孩子。

#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<utility>
using namespace std; int main()
{
vector<string> student;
map<string,vector<string>> family;
string firstname;
string lastname;
/*while(cin>>lastname&&lastname!="0")
{
family.insert(make_pair(lastname,student));
}*/
while(cin>>lastname)
{
while(cin>>firstname&&firstname!="\n)
family[lastname].push_back(firstname);
} for(auto s:family)
{
cout<<s.first<<" firstname ";
for(auto r:s.second)
cout<<r<<" ";
cout<<endl;
}
return ;
}

map的例子的更多相关文章

  1. Scala中的Map使用例子

    Map结构是一种非常常见的结构,在各种程序语言都有对应的api,由于Spark的底层语言是Scala,所以有必要来了解下Scala中的Map使用方法. (1)不可变Map特点: api不太丰富 如果是 ...

  2. 提高Baidu Map聚合的效率

    百度的MAP的例子里提供了一个聚合效果,地址是http://developer.baidu.com/map/jsdemo.htm#c1_4 ,效果图如下图: 这个效果很赞,但效率很低,当数据量达到50 ...

  3. 数组map()方法和filter()方法及字符串startsWith(anotherString)和endsWith(anotherString)方法

    map方法的作用不难理解,"映射"嘛,也就是原数组被"映射"成对应新数组 var newArr = arr.map(function() {});例子: var ...

  4. JAVA基础--容器 Set, List, Map

    Colections接口, Iterator接口, Set接口, List接口, Comparable接口, Map接口 Collections类 容器:装各种对象. 所有容器都在java.util里 ...

  5. 4.Java集合总结系列:Map接口及其实现

    一.Map接口 Map集合的特点是:通过key值找到对应的value值,key值是唯一的,value可以重复.Map中的元素是无序的,但是也有实现了排序的Map实现类,如:TreeMap. 上面Map ...

  6. C++ STL map详解

    一.解释: p { margin-bottom: 0.25cm; direction: ltr; color: #00000a; line-height: 120%; text-align: just ...

  7. 匿名函数lambda,过滤函数filter,映射类型map

    匿名函数lambda, 作用是不用定义函数,用完之后会自动被删掉,在使用执行脚本的时候,使用lambda就可以省下定义函数的过程,简化代码的可读性. 格式是 例子g=lambda x,y:x+y g( ...

  8. python 函数式编程之lambda( ), map( ), reduce( ), filter( )

    lambda( ), map( ), reduce( ), filter( ) 1. lambda( )主要用于“行内函数”: f = lambda x : x + 2 #定义函数f(x)=x+2 g ...

  9. Python面试题之Python中的lambda map filter reduce zip

    当年龟叔想把上面列出来的这些都干掉.在 “All Things Pythonic: The fate of reduce() in Python 3000”这篇文章中,他给出了自己要移除lambda. ...

随机推荐

  1. 对加密方式(公钥私钥)的形象理解(以http和https为例)

    https其实就是建构在SSL/TLS之上的 http协议,所以要比较https比http多用多少服务器资源,主要看SSL/TLS本身消耗多少服务器资源. http使用TCP 三次握手建立连接,客户端 ...

  2. js中JSON对象和字符串对象相互转化

    JSON.stringify(value [, replacer] [, space]) //作用,将json数据转化为字符串value:是必须要的字段.就是你输入的对象,比如数组啊,类啊等等. re ...

  3. WCF - IIS Hosting

    WCF - IIS Hosting Hosting a WCF service in IIS (Internet Information Services) is a step-by-step pro ...

  4. 校园网之MentoHUST安装与使用

    作用:MentoHUST可以解决校园网锐捷客户端与Windows的兼容性问题,可以解决安装虚拟机之后虚拟机网卡与本地网卡冲突的问题,可以做到愉快的用校园网,并可以愉快的用校园网开Wifi给自己或者小伙 ...

  5. 修饰模式(Decorator结构型)C#简单例子

    修饰模式(Decorator结构型)C#简单例子 玩家基本功能是移动.运行等等.BaseAbility新增加功能:1.伤害技能harmAbility:2.阻碍技能BaulkAbility:3.辅助技能 ...

  6. 【转】Mac QQ截图保存在哪里?

    原文网址:http://www.pc6.com/edu/67677.html QQ Mac版的截屏图片保存在哪儿呢?可不可以像Windows版本一样设定保存路径呢?当然是可定的.Mac QQ截图保存你 ...

  7. 【转】Android 学习笔记——利用JNI技术在Android中调用、调试C++代码

    原文网址:http://cherishlc.iteye.com/blog/1756762 在Android中调用C++其实就是在Java中调用C++代码,只是在windows下编译生成DLL,在And ...

  8. zookeeper使用和原理探究(一)(转)

    zookeeper介绍zookeeper是一个为分布式应用提供一致性服务的软件,它是开源的Hadoop项目中的一个子项目,并且根据google发表的<The Chubby lock servic ...

  9. Java&MySQL Type Mapping

    MySQL Type Name Return value of GetColumnClassName Returned as Java Class BIT(1) (new in MySQL-5.0) ...

  10. Storm系列(十五)架构分析之Executor-Spout

    Spout实现mk-threads接口用于创建与Executor对应的消息循环主函数. defmulti mk-threads executor-selector Mk-threads函数的主消息循环 ...