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. 洗礼灵魂,修炼python(84)-- 知识拾遗篇 —— 网络编程之socket

    学习本篇文章的前提,你需要了解网络技术基础,请参阅我的另一个分类的博文:网络互联技术(4)——计算机网络常识.原理剖析 网络通信要素 1.IP地址: 用来标识网络上一台独立的终端(PC或者主机) ip ...

  2. UICollectionView 基础

    在iOS开发中经常会用到UICollectionView,和UITableView同样即成UIScrollView 但是操作起来比UITableVIew要麻烦一些 ,有些地方需要注意,一下是UICol ...

  3. 【Git 学习三】深入理解git reset 命令

    重置命令(git reset)是Git 最常用的命令之一,也是最危险最容易误用的命令.来看看git reset命令用法. --------------------------------------- ...

  4. ctf学习(web题二)

    web 下面是做bugku上一些web的总结 内容链接

  5. Nginx location配置详解

    上一篇博客Nginx配置详解已经说过了nginx 的基本配置情况,今天来详细讲述一下nginx的location的配置原则, location是根据Uri来进行不同的定位,location可以把网站的 ...

  6. PHP匿名函数

    PHP匿名函数 匿名函数(Anonymous functions),也叫闭包函数(closures),允许临时创建一个没有指定名称的函数.最经常用作回调函数(callback)参数的值. 举例: &l ...

  7. February 25th, 2018 Week 9th Sunday

    LIfe is about making an impact, not making an income. 生命在于影响他人,而非赚钱糊口. From Kevin Kruse. You probabl ...

  8. February 17th, 2018 Week 7th Saturday

    The happiest part of a man's life is what he passes lying awake in bed in the morning. 人生一大乐事莫过去早上醒来 ...

  9. WIndows 使用VS编译 Lua5

    从Lua5.1开始官方给出的文件只有源代码和makefile文件了,官网给出的bulid方式也是在linux平台,如果只是想找个库使用下可以到这里来下载:http://joedf.ahkscript. ...

  10. Ubuntu 12.04上安装R语言

    Ubuntu 12.04上安装R语言 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ R的安装 sudo gedit /etc/apt/sources. ...