关联容器set,multimap以及函数对象

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdlib>
#include<utility>
#include<set>
#include<map>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<functional>
#include"windows.h"
using namespace std;
void show(const int n){ cout << n << " "; }
bool Lower5(const int &n){return n > 5;}//利用谓词来做remove_if()判断
class Upperx
{
private:
	int bound;
public:
	Upperx(const int &n) :bound(n){};
	bool operator()(const int &value){ return value <= bound; }//重载运算符()
};
int main()
{
	string str1[] = { "beijing", "shanghai", "chongqing" };
	string str2[] = { "nanjing", "heifei", "beijing" };
	set<string>s1(str1, str1 + 3);
	cout << "Original s1: ";
	ostream_iterator<string,char>out(cout, " ");
	copy(s1.begin(), s1.end(), out);
	cout << endl;
	string str3 = "shenzhen";
	set<string>s2(str2, str2 + 3);
	cout << "Original s2: ";
	copy(s2.begin(), s2.end(),out);
	cout << endl;
	s2.insert(str3);//集合原本就默认排序,所以不需要指定插入位置
	cout << "After s2.insert(str3), s2: ";
	copy(s2.begin(), s2.end(), out);
	cout << endl;
	cout << "s1+s2=";
	set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), out);
	cout << endl;
	cout << "s1^s2=";
	set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), out);
	cout << endl;
	cout << "s1-s2=";
	set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), out);
	cout << endl;
	cout << "great_equal or great anhui: ";
	copy(s1.lower_bound("anhui"), s1.upper_bound("jiangsu"), ostream_iterator<string, char>(cout, " "));
	cout << endl;
	multimap<int, string>mm;
	vector<pair<int, string>>v;
	v.push_back(pair<int, string>(8, "huainan"));
	v.push_back(pair<int, string>(12, "wuhu"));
	v.push_back(pair<int, string>(12, "huaibei"));
	mm.insert(pair<int, string>(12, "hefei"));
	mm.insert(v.begin(), v.end());
	for (auto y : mm)
		cout << "No." << y.first << ",Name:"<<y.second << endl;
	cout << "the count of No.12: " << mm.count(12) << endl;
	pair<multimap<int, string>::iterator, multimap<int, string>::iterator>range
		= mm.equal_range(12);
	cout << "No.12: ";
	for (auto x = range.first; x != range.second; x++)
		cout << (*x).second<<" ";
	cout << endl;
	int num[] = { 3, 5, 6, 2, 7 };
	list<int>li(num,num+5);
	cout << "Original list:";
	for_each(li.begin(), li.end(), show);
	cout << endl;
	li.remove_if(Lower5);
	cout << "li.remove_if(Lower5):";
	for_each(li.begin(), li.end(), show);
	cout << endl;
	li.insert(li.begin(), num, num + 5);
	Upperx Upper(5);
	li.remove_if(Upper);//利用类重载的()运算符
	cout << "li.remove_if(Upper):";
	for_each(li.begin(), li.end(), show);
	cout << endl;
	cout << "The first form of transform(one-elem function): ";
	transform(li.begin(), li.end(), ostream_iterator<double,char>(cout," "), sqrt<int>);//transform调用的一元函数
	cout << endl;
	list<int>result;
	list<int>li2(num + 3, num + 5);
	cout << "The second form of transform(two-elem function): ";
	transform(li.begin(), li.end(), li2.begin(), insert_iterator<list<int>>(result, result.begin()), multiplies<int>());
	copy(result.begin(), result.end(), ostream_iterator<int, char>(cout, " "));
	cout << endl;
	cout << "The third form of transform(adaptive function->two-elem to one-elem): ";
	transform(li.begin(), li.end(), ostream_iterator<double, char>(cout, " "), bind1st(multiplies<double>(), 2.5));
	cout << "\nDone!\n";
	system("pause");
  return 0;
}

程序运行结果如下

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的精简博客系统,源码+数据库+毕业论文+视频演示 当下,正处于信息化的时代,许多行业顺应时代的变化,结合使用计算机技术向数字化、信息化建设迈进。以前企业对于博客信息的管理和控制,采用人工登记的方式保存相关数据,这种以人力为主的管理模式已然落后。本人结合使用主流的程序开发技术,设计了一款基于Springboot开发的精简博客系统,可以较大地减少人力、财力的损耗,方便相关人员及时更新和保存信息。本系统主要使用B/S开发模式,在idea开发平台上,运用Java语言设计相关的系统功能模块,MySQL数据库管理相关的系统数据信息,SpringBoot框架设计和开发系统功能架构,最后通过使用Tomcat服务器,在浏览器中发布设计的系统,并且完成系统与数据库的交互工作。本文对系统的需求分析、可行性分析、技术支持、功能设计、数据库设计、功能测试等内容做了较为详细的介绍,并且在本文中也展示了系统主要的功能模块设计界面和操作界面,并对其做出了必要的解释说明,方便用户对系统进行操作和使用,以及后期的相关人员对系统进行更新和维护。本系统的实现可以极大地提高企业的工作效率,提升用户的使用体验,因此在现实生活中运用本系统具有很大的使用价值。 关键词:博客管理;Java语言;B/S结构;MySQL数据库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值