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 ;
}
随机推荐
- Linux C语言编程学习笔记 (1)进程控制入门
想进行Linux系统开发已经很久了,一直没有付诸实践.今日终于开始学习Linux下的C语言编程,研究一天,终于大概弄明白了Linux系统进程管理的一些基本概念和编程方法,总结下来以方便大家学习和自己实 ...
- 接口开发-集成数据库操作(mybatis)
关于数据存储,最常用的方式就是存到数据库,此篇以MySQL数据库为例,以mybatis框架完成数据库的操作. 一.添加对应依赖 <!-- 数据库:MySQL --> <depende ...
- CentOS启动OpenVPN报错:Failed to start OpenVPN Robust And Highly Flexible Tunneling Application On server.
tailf /var/log/openvpn.log 查看日志,里面有最详细的错误解说. 参考: https://forums.openvpn.net/viewtopic.php?t=21561
- C#中POST数据和接收的几种方式
POST方式提交数据,一种众所周知的方式: html页面中使用form表单提交,接收方式,使用Request.Form[""]或Request.QueryString[" ...
- stanford CS DB 课程 数据库系统实现
http://infolab.stanford.edu/db_pages/classes.html CS145: Introduction to Databases CS245: Databa ...
- poj2115
构造出模线性方程c * x = b - a mod (2 ^ k) 很容易解. 利用LRJ书上的方法. #include <iostream> using namespace std; # ...
- Win10年度更新开发必备:VS2015 Update 1正式版下载汇总
微软在12月1日发布了Visual Studio 2015 Update 1 .在MSDN中微软也提供下载,而且MSDN的Visual Studio 2015 Update 1与官方免费下载的文件是一 ...
- hdu1716排列2(stl:next_permutation+优先队列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- AngularJS报错:[$injector:unpr] Unknown provider: $templateRequestProvider
在页面中由上到下引用了: angular.js angular-route.js 创建model的时候也写明了依赖: var someApp = angular.module('someApp',[' ...
- 解决警告 warning: directory not found for option
解决方法: 选择项目名称----->Targets----->Build Settings----->Search Paths----->Library Search Path ...