map的例子
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的例子的更多相关文章
- Scala中的Map使用例子
Map结构是一种非常常见的结构,在各种程序语言都有对应的api,由于Spark的底层语言是Scala,所以有必要来了解下Scala中的Map使用方法. (1)不可变Map特点: api不太丰富 如果是 ...
- 提高Baidu Map聚合的效率
百度的MAP的例子里提供了一个聚合效果,地址是http://developer.baidu.com/map/jsdemo.htm#c1_4 ,效果图如下图: 这个效果很赞,但效率很低,当数据量达到50 ...
- 数组map()方法和filter()方法及字符串startsWith(anotherString)和endsWith(anotherString)方法
map方法的作用不难理解,"映射"嘛,也就是原数组被"映射"成对应新数组 var newArr = arr.map(function() {});例子: var ...
- JAVA基础--容器 Set, List, Map
Colections接口, Iterator接口, Set接口, List接口, Comparable接口, Map接口 Collections类 容器:装各种对象. 所有容器都在java.util里 ...
- 4.Java集合总结系列:Map接口及其实现
一.Map接口 Map集合的特点是:通过key值找到对应的value值,key值是唯一的,value可以重复.Map中的元素是无序的,但是也有实现了排序的Map实现类,如:TreeMap. 上面Map ...
- C++ STL map详解
一.解释: p { margin-bottom: 0.25cm; direction: ltr; color: #00000a; line-height: 120%; text-align: just ...
- 匿名函数lambda,过滤函数filter,映射类型map
匿名函数lambda, 作用是不用定义函数,用完之后会自动被删掉,在使用执行脚本的时候,使用lambda就可以省下定义函数的过程,简化代码的可读性. 格式是 例子g=lambda x,y:x+y g( ...
- python 函数式编程之lambda( ), map( ), reduce( ), filter( )
lambda( ), map( ), reduce( ), filter( ) 1. lambda( )主要用于“行内函数”: f = lambda x : x + 2 #定义函数f(x)=x+2 g ...
- Python面试题之Python中的lambda map filter reduce zip
当年龟叔想把上面列出来的这些都干掉.在 “All Things Pythonic: The fate of reduce() in Python 3000”这篇文章中,他给出了自己要移除lambda. ...
随机推荐
- Android:Fragment+ViewPager实现Tab滑动
public class FragAdapter extends FragmentPagerAdapter { private List<Fragment> fragments ; pub ...
- 【原创】MIPS·Verilog·FPGA
时至今日,终于将全部的计划55条MIPS指令在FPGA上全部验证完毕,通过这近一个月的不断的修改调试.修改调试,我对整个流程对MIPS有了深刻的体会和认识.借着刚刚现阶段任务的兴奋和短暂的空闲时间,将 ...
- windows平台下VLC2.0.5编译
windows平台下VLC2.0.5编译说明 时隔一年多,又要搞流媒体了,不过这次是要做流媒体服务器. 暂时决定使用vlc+ffmpeg+live555,虽然听有些前辈说这个组合的性能较差,只能作为学 ...
- 机器学习&深度学习经典资料汇总,data.gov.uk大量公开数据
<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost到随机森林.D ...
- hadoop2.2编程:Tool, ToolRunner, GenericOptionsParser, Configuration
继承关系: 1. java.util Interface Map.Entry<K,V> description: public static interface Map.Entry&l ...
- 一步步写STM32 OS【二】环境搭建
一.安装IAR for ARM6.5 二.新建工程 1.选择处理器:STM32F407VG,暂不使用FPU 2.必要的路径配置和宏定义 3.使用SWO重定向IO输出 4.使用ST-LINK仿真器 5. ...
- Async callback to awaitable Task<> z
http://blog.tedd.no/2013/09/13/async-callback-to-awaitable-task/ The Async-Await feature in .Net is ...
- hdu-5364 Distribution money
http://acm.hdu.edu.cn/showproblem.php?pid=536 Distribution money Time Limit: 2000/1000 MS (Java/Othe ...
- oracle 物化视图及创建索引
物化视图是一种特殊的物理表,“物化”(Materialized)视图是相对普通视图而言的.普通视图是虚拟表,应用的局限性大,任何对视图的查询,Oracle都实际上转换为视图SQL语句的查询.这样对整体 ...
- Entity Framework 杂碎
其实看图很简单,database first和model first都是通过 data model创建的edmx文件,只不过model first模块可以自己根据需要创建和修改实体,显得更加灵活. c ...