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. 145. Binary Tree Postorder Traversal

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given bina ...

  2. scaleform 注意事项

    在使用 自带的UI .fla 里面的组建时 需要把自己建立的fla进行如下设置.  文件-发布设置-flash-脚本actionscript3.0设置——舞台:自动声明舞台实例    

  3. Oracle Java SE远程安全漏洞(CVE-2013-5878)

    漏洞版本: Oracle Java SE 7u45 Oracle Java SE 6u65 漏洞描述: BUGTRAQ ID: 64927 CVE(CAN) ID: CVE-2013-5878 Jav ...

  4. iOS添加自定义字体方法

    1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...

  5. [Android] An internal error occurred during: "Launching New_configuration". Path for project must have only one segment.

    出错: An internal error occurred during: "Launching New_configuration". Path for project mus ...

  6. CLR C++ Set Word CustomDocumentProperties

    // WordIssue.cpp : main project file. #include "stdafx.h" using namespace System; using na ...

  7. 从微信推送看Android Service的创建和销毁

    启动服务是有两组参数影响服务的状态. 1.在onStartCommand(Intent intent, int flags, int startId) 接口中返回值,例如 START_STICKY;  ...

  8. 多控制器之UIWindow

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  9. iOS版 feedly 无法使用gmail账户的解决办法

    印象中很长时间以来,iOS版 Feedly 总是使用不了gmail账户,原因就在于打不开登录界面.但奇怪的是在PC上又正常……非常无语!手机和PC真是两个不同的世界啊 其它RSS阅读软件不是收费,就是 ...

  10. 【解决】Microsoft Visual Studio 2012 打开2008下编译的silverlight3项目

    最近因为项目需要,老师要我搞一发流程设计器,毫无头绪呀妈蛋 .. 我考虑是用silverlight呢还是jquery .. 上网找了找  .. 有一个用silverlight3写的 貌似IDE用的是V ...