set

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
//vector学习
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("in.txt","r",stdin);
set<int> se;
int x,n;
printf("输入n:\n");
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x;
se.insert(x);
}
cout<<"有多少个元素:\n";
cout<<se.size()<<endl;
cout<<"遍历set:\n";
for(set<int>::iterator i=se.begin();i!=se.end();i++)
cout<<*i<<' ';
cout<<endl;
cout<<"有多少个5在里面:\n";
cout<<se.count(5)<<endl;
cout<<"是否存在112和23:\n";
cout<<*se.find(112)<<' '<<*se.find(23)<<endl;
cout<<"查找第一个大于或等于5\n";
cout<<*se.lower_bound(5)<<endl;
cout<<"查找第一个大于5的下:\n";
cout<<*se.upper_bound(5)<<endl; return 0;
}

multiset

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
//vector学习
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("in.txt","r",stdin);
multiset<char> se;
int n;
char x;
printf("输入n:\n");
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x;
se.insert(x);
}
cout<<"有多少个元素:\n";
cout<<se.size()<<endl;
cout<<"遍历set:\n";
for(set<char>::iterator i=se.begin();i!=se.end();i++)
cout<<*i<<' ';
cout<<endl;
cout<<"有多少个5在里面:\n";
cout<<se.count('c')<<endl; return 0;
}

set和multiset的用法的更多相关文章

  1. CF994B Knights of a Polygonal Table 第一道 贪心 set/multiset的用法

    Knights of a Polygonal Table time limit per test 1 second memory limit per test 256 megabytes input ...

  2. set/multiset和map/multimap用法小结

    二叉搜索树是ACM中经常需要用到的数据结构,熟练掌握map和set的用法很关键,现对其做一个简单的总结. 主要的功能有:插入元素,查找元素,删除,遍历/反向遍历. 插入,删除和查找操作的时间都和树的高 ...

  3. 关于set和multiset的一些用法

    set的一些用法 set的特性 set的特性是,所有元素都会根据元素的键值自动排序,set不允许两个元素有相同的键值. set的一些常用操作函数 insert() insert(key_value); ...

  4. 4.2 set和multiset

    使用必须包含头文件set 1)multiset *:定义 如果不给第二个参数,默认less<key>,即用<来进行. 例如: A是一个类的名字,则可以定义一个容器对象如下: mult ...

  5. c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏

    c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...

  6. C++11中map的用法

    最全的c++map的用法 1. map最基本的构造函数:map<string ,int>mapstring; map<int,string >mapint;map<sri ...

  7. POJ 3096 Surprising Strings(STL map string set vector)

    题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...

  8. POJ 1552 Doubles (C++ STL set使用)

    题目: 题意:题意:给出几个正数(2~15个),然后就是求有这些数字的2倍有没有和原先的正数相同的,求出有几个,没有就是0. 分析:水题.用数组解决,开一个数组存正数,另开一个数组用来存这些数的2倍, ...

  9. [Swust OJ 1094]--中位数(巧用set,堆排序)

    题目链接:http://acm.swust.edu.cn/problem/1094/ Time limit(ms): 1000 Memory limit(kb): 32768   中位数(又称中值,英 ...

随机推荐

  1. sqlserver waitfor time 延迟函数的用法

    SQL有定时执行的语句 WaitFor,可以写到一个存储过程中再执行一次 语法:WaitFor{Delay 'time'|Time 'time} Delay后面的时间为延迟多少时间执行 Time后面的 ...

  2. AngularJS学习之旅—AngularJS 指令(三)

    1.AngularJS 指令 AngularJS 通过被称为 指令 的新属性来扩展 HTML. AngularJS 通过内置的指令来为应用添加功能. AngularJS 允许你自定义指令.2.Angu ...

  3. 数据挖掘---Numpy的学习

    什么是Numpy NumPy系统是Python的一种开源的数值计算扩展.这种工具可用来存储和处理大型矩阵(任意维度的数据处理),比Python自身的嵌套列表(nested list structure ...

  4. MY Views on Doctor-patient relationship 英语医患关系议论文

    MY Views on Doctor-patient relationship Author:Pleiades_Antares(www.cnblogs.com/irischen) 1. In rece ...

  5. 为JQuery EasyUI 表单组件加上“清除”功能

    1.背景 在使用 EasyUI 各表单组件时,尤其是使用 ComboBox(下拉列表框).DateBox(日期输入框).DateTimeBox(日期时间输入框)这三个组件时,经常有这样的需求,下拉框或 ...

  6. X的平方根的golang实现

    实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 输入: 输出: 输入: 输出: 说明: 的 ...

  7. (1)Python基础

    几种常用类型 int float str bool 基本数值操作 绝对值 abs 四舍五入 round 最大值&最小值

  8. centos7下安装docker(17.3docker监控---cAdvisor)

    cAdvisor是google开发的容器监控工具 1.在host上运行cadvisor容器 docker run -d -p 8080:8080 --name cadvisor -v /:/rootf ...

  9. Gps定位和wifi定位和基站定位的比较

    现在手机定位的方式是:Gps定位,wifi定位,基站定位 Gps定位的前提,手机开启Gps定位模块,在室外,定位的精度一般是几米的范围 wifi定位的前提,手机要开启wifi,连不连上wifi热点都可 ...

  10. .net core 2.1 Razor 超快速入门

    以下过程如有不明白的,可参考:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/razor-pages/?view=aspnetcore-2 ...