set基本用法-----2
2024-09-22 12:17:47
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<stack>
#include<set>
#define maxn +50
#define inf 0x7fffffff
#define xiao 1e-9
using namespace std;
set<int>::iterator iter;
int main()
{
int a[]={,,};
set<int> s;
s.insert(a,a+);//与set<int> s(a,a+3); 等效
//s.find()查找set中是否有这个数,iter是它的位置,如果有则返回iter ,没有则返回s.end();
{ if((iter=s.find())!=s.end())
{
cout<<*iter<<endl;
}
}
//insert(first,second) 把定位器first 与second之间的值插入set中 ,返回值为空
{
for(iter=s.begin();iter!=s.end();++iter) cout<<*iter<<" ";
cout<<endl;
}
//insert(key_value)返回值是pair<set<int>::iterator,bool>,bool代表是否插入成功,iterator代表插入的位置,若key_value已经在set中,则iterator返回所在位置
{
pair<set<int>::iterator,bool> pr;
pr=s.insert();
if(pr.second) cout<<*pr.first<<endl;
}
//lower_bound(key_value)返回第一个大于等于key_value的值的位置
//upper_bound(key_value)返回最后一个大于等于key_value的值的位置
{
cout<<*s.lower_bound()<<endl;
cout<<*s.upper_bound()<<endl;
}
return ;
}
set真是一个神奇的东西~~~~~
最新文章
- C语言-占位符
- C# 读取EXCEL文件的三种经典方法
- Hadoop执行作业时报错:java.lang.OutOfMemoryError: Java heap space
- Highlighting System
- QFtp类参考
- linux centos 安装
- mybatis include标签
- 【CF】7 Beta Round D. Palindrome Degree
- oracle 常用博客网址
- native跟volatile
- SMO(Sequential Minimal Optimization) 伪代码(注释)
- HTTP中的URL长度限制(资料整理)
- MIT6.828 虚拟地址转化为物理地址——二级分页
- Masonry使用详解
- [07] ServletContext上下文对象
- WIndows下使用Grafana+InfluxDB打造监控系统
- 尚硅谷springboot学习26-嵌入式servlet容器自动配置、启动原理
- 双网卡Iptables端口转发
- Java零基础教程(二)基础语法
- Oslo 相机 App