set和multiset的用法
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的用法的更多相关文章
- 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 ...
- set/multiset和map/multimap用法小结
二叉搜索树是ACM中经常需要用到的数据结构,熟练掌握map和set的用法很关键,现对其做一个简单的总结. 主要的功能有:插入元素,查找元素,删除,遍历/反向遍历. 插入,删除和查找操作的时间都和树的高 ...
- 关于set和multiset的一些用法
set的一些用法 set的特性 set的特性是,所有元素都会根据元素的键值自动排序,set不允许两个元素有相同的键值. set的一些常用操作函数 insert() insert(key_value); ...
- 4.2 set和multiset
使用必须包含头文件set 1)multiset *:定义 如果不给第二个参数,默认less<key>,即用<来进行. 例如: A是一个类的名字,则可以定义一个容器对象如下: mult ...
- 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 ...
- C++11中map的用法
最全的c++map的用法 1. map最基本的构造函数:map<string ,int>mapstring; map<int,string >mapint;map<sri ...
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- POJ 1552 Doubles (C++ STL set使用)
题目: 题意:题意:给出几个正数(2~15个),然后就是求有这些数字的2倍有没有和原先的正数相同的,求出有几个,没有就是0. 分析:水题.用数组解决,开一个数组存正数,另开一个数组用来存这些数的2倍, ...
- [Swust OJ 1094]--中位数(巧用set,堆排序)
题目链接:http://acm.swust.edu.cn/problem/1094/ Time limit(ms): 1000 Memory limit(kb): 32768 中位数(又称中值,英 ...
随机推荐
- 洗礼灵魂,修炼python(84)-- 知识拾遗篇 —— 网络编程之socket
学习本篇文章的前提,你需要了解网络技术基础,请参阅我的另一个分类的博文:网络互联技术(4)——计算机网络常识.原理剖析 网络通信要素 1.IP地址: 用来标识网络上一台独立的终端(PC或者主机) ip ...
- 关于java中assert(断言)的使用讲解
说明:写的不是很全面,有任何问题请留言,多交流,谢谢! 1.eclipse.myeclipse开启assert(断言),默认是关闭,如下: 说白了就是设置一下jvm的参数,参数是-ea或者-enabl ...
- 一个tomcat部署多个应用实例
安装JDK7sudo apt-get install java7-jdk 安装tomcat7 Tomcat7下载地址http://mirror.bjtu.edu.cn/apache/tomcat/to ...
- JavaScript显示文本框后自动获取焦点
废话少说,见官方文档: 他的用法是:document.getElementById('username').focus(); 这样写在display:block;显 ...
- 前端性能优化成神之路-HTTP压缩开启gzip
什么是HTTP压缩 HTTP压缩是指: Web服务器和浏览器之间压缩传输的”文本内容“的方法. HTTP采用通用的压缩算法,比如gzip来压缩HTML,Javascript, CSS文件. 能大大减少 ...
- Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices
C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes i ...
- Linux CenterOS安装mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz步骤
1.首先配置IP. Cd /etc/sysconfig/network-scripts/ vim ifcfg-ens32 将ONBOOT=no,改为ONBOOT=yes.(开机启动激活网卡) 2.构建 ...
- (1)Python基础
几种常用类型 int float str bool 基本数值操作 绝对值 abs 四舍五入 round 最大值&最小值
- Tesseract-OCR识别
参考 https://studygolang.com/topics/4527/comment/13217 安装版Windows下链接: https://digi.bib.uni-mannheim.de ...
- UVA1442-Cav(扫描法)
Problem UVA1442-Cav Accept: 185 Submit: 679Time Limit: 3000 mSec Problem Description Input The inpu ...