set的用法 STL
来源:互联网 发布:linux ldconfig 编辑:程序博客网 时间:2024/05/17 22:07
MZL's simple problem
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 297 Accepted Submission(s): 134
Problem Description
You have a multiple set,and now there are three kinds of operations:
1 x : add number x to set
2 : delete the minimum number (if the set is empty now,then ignore it)
3 : query the maximum number (if the set is empty now,the answer is 0)
Next
The number in this set is not greater than
61 21 331 31 43
34
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
set<int>d;
int main()
{
int n;
scanf("%d", &n);
d.clear();
while (n--)
{
int m;
scanf("%d", &m);
if (m == 1)
{
int t;
scanf("%d", &t);
d.insert(t);
}
if (m == 2)
{
if (!d.empty())
d.erase(d.begin());
}
if (m == 3)
{
if (d.empty())
printf("0\n");
else
printf("%d\n", *(--d.end()));
}
}
return 0;
}
1,set的含义是集合,它是一个有序的容器,里面的元素都是排序好的,支持插入,删除,查找等操作,就
2,Set中的元素可以是任意类型的,但是由于需要排序,所以元素必须有一个序,即大小的比较关系,比如
3,自定义比较函数;
4,set的基本操作:
begin()
clear()
count()
empty()
end()
equal_range()
erase()
find()
get_allocator() 返回集合的分配器
insert()
lower_bound()
key_comp()
max_size()
rbegin()
rend()
size()
swap()
upper_bound()
value_comp()
5,自定义比较函数:
For example:
#include<iostream>
#include<set>
using namespace std;
typedef struct {
int a,b;
char s;
}newtype;
struct compare
{
bool operator()(const newtype &a, const newtype &b) const
{
return a.s<b.s;
}
};//the “; ”
set<newtype,compare>element;
int main()
{
newtype a,b,c,d,t;
a.a=1; a.s='b';
b.a=2; b.s='c';
c.a=4; c.s='d';
d.a=3; d.s='a';
element.insert(a);
element.insert(b);
element.insert(c);
element.insert(d);
set<newtype,compare>::iterator it;
for(it=element.begin(); it!=element.end();it++)
cout<<(*it).a<<" ";
cout<<endl;
for(it=element.begin(); it!=element.end();it++)
cout<<(*it).s<<" ";
}
element自动排序是按照char s的大小排序的;
6.其他的set构造方法;
#include <iostream>
#include <set>
using namespace std;
bool fncomp (int lhs, int rhs) {return lhs<rhs;}
struct classcomp {
};
int main ()
{
- STL set的用法
- stl set的用法
- set的用法 STL
- STL set的用法总结
- STl 中set的用法
- STL中set的用法
- STL set的用法总结
- STL之 set的用法
- STL之set 的用法
- STL的set基本用法
- STL中的set的用法
- STL的set详尽用法
- STL之Set:Set的基本用法
- STL之Set:Set的基本用法
- STL之Set:Set的基本用法
- C++ STL set::find的用法
- C++ STL set::find的用法
- STL set和multiset的用法
- memcache 是如何实现分布式存储的?
- AFN获取cookie与设置cookie
- leetcode 376. Wiggle Subsequence
- poj 1789 (最小生成树 Prime)
- Linux 中的零拷贝技术,第 1 部分
- set的用法 STL
- RC中资源更换
- Js 冒泡事件阻止
- 扩展欧几里德算法
- java反编译
- Python学习笔记一 基本语法、变量类型、时间处理
- 【刷题之路】连续子数组的最大和
- POJ - 1042 Gone Fishing(钓鱼)(深搜+贪心)
- java多态,如何理解父类引用指向子类对象