set练习
#include <iostream>
#include <set>
#include <vector> using namespace std; int main()
{
set<int> setInt;
vector<int> ivec;
for(vector<int>::size_type i = 0; i != 11; ++i)
ivec.push_back(i);
setInt.insert(ivec.begin(), ivec.end());
setInt.insert(11);
set<int>::iterator itor1 = setInt.find(9);// 这个也对,为什么const类型的键值可以用非const的迭代器?????
set<int>::const_iterator itor2 = setInt.find(10);
if(itor1 != setInt.end())
cout << *itor1 << endl;
/*
*itor1 = 12; //error:keys in a set are read-only 正如不能修改mao中元素的键部分一样,set中的键也是const,在获取迭代器后只能对其进行读操作
*/
if(itor2 != setInt.end())
cout << *itor2 << endl;
system("pause");
return 0;
}
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map> using namespace std; void restricted_wc( vector<string> strVec, map<string, int> &wordCount )
{
// create a set of excluded words
set<string> excluded;
for ( vector<string>::iterator it = strVec.begin(); it != strVec.end(); ++it )
{
excluded.insert( *it );
} string word;
cout << " Input some words to count the words in wordCount(map) ( ctrl + z to end): "
<< endl;
cin.clear();
while ( cin >> word )
{
if ( !excluded.count( word ) )
++wordCount[ word ];
}
} int main(int argc, char* argv[])
{
cout << " Input some words to vector<string> excluded ( ctrl + z to end): " << endl;
vector<string> excludedVec;
string excludedWord;
while ( cin >> excludedWord )
excludedVec.push_back( excludedWord ); // use restricted_wc()
map< string, int > wordCount;
restricted_wc( excludedVec, wordCount ); // show out the map:wordCount
cout << "\n\tShow out the map:wordCount: " << endl;
for ( map< string, int >::iterator it = wordCount.begin(); it != wordCount.end(); ++it )
{
cout << " The word '" << (*it).first << "' appears for " << (*it).second << " times. " << endl;
} system("pause");
return ;
}
随机推荐
- BugkuCTF ---游戏过关 writeup
下载程序后发现是输入1-8数字中的一位 至于怎么玩,我到现在都没弄懂 不多说,直接拖入Ollydbg 搜索 分析了一下字符串,发现有一个显示flag的字符串 双击过去看看,发现类似于一个函数. 接下来 ...
- 自动添加 Qt 开发生成的 exe 所需的依赖环境
双击获取 exe 文件路径 cd 进入文件目录的命令 调用 Qt 自带的软件进行环境配置,命令如下 windeployqt ***.exe 自动配置了依赖环境
- ios数据保存
- 微信小程序开发需要注意的29个坑
1.小程序名称可以由中文.数字.英文.长度在3-20个字符之间,一个中文字等于2个字符. 2.小程序名称不得与公众平台已有的订阅号.服务号重复.如提示重名,请更换名称进行设置. 3.小程序名称在帐号信 ...
- Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer capture input channel.
Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer ca ...
- Ubuntu 14 安装Java(JRE、JDK)、Maven
JRE vs OpenJDK vs Oracle JDK JRE(Java Runtime Environment),它是你运行一个基于Java语言应用程序的所正常需要的环境.如果你不是一个程序员的话 ...
- EF Core数据迁移操作
摘要 在开发中,使用EF code first方式开发,那么如果涉及到数据表的变更,该如何做呢?当然如果是新项目,删除数据库,然后重新生成就行了,那么如果是线上的项目,数据库中已经有数据了,那么删除数 ...
- [Git]git教程
摘要 目前公司项目逐渐都要迁移到git上,使用git进行版本控制及源代码管理. git学习资料 一个小时学会Git 权威Git书籍ProGit(中文版) git官网:http://git-scm.co ...
- 为什么我不再用 .NET 框架
.NET平台很棒.真的很棒.直到它不再那么棒.我为什么不再用.NET?简单来说,它限制了我们选择的能力(对我来说很重要),转移了我们的注意力,使得我们向内认知它的安全性,替代了帮助我们认知外面广阔世界 ...
- 加快Qemu Aarch32虚拟开发板的启动速度
软件版本 Qemu: 2.8.0 虚拟开发板: vexpress-ca9 概述 之前的博文介绍了将Python移植到开发板上, 根文件系统采用的是ramdisk, 这个文件系统的缺点是修改的内容重启会 ...