Problem B: STL——多重集的插入和删除
来源:互联网 发布:淘宝c店详情页尺寸 编辑:程序博客网 时间:2024/05/17 08:26
Problem B: STL——多重集的插入和删除
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1356 Solved: 973
[Submit][Status][Web Board]
Description
给你一个集合,一开始集合是空集,然后进行若干操作,最后你要从小到大输出集合中的元素,以空格隔开。(集合中可能会有相同元素)
Input
一共有若干输入数据,开头一个n(n<=20),n=0代表输入结束。
然后有n行,每行有2种形式:
“i x”,x是一个整数,代表向集合中插入元素x
“d x”,x是一个整数,代表删除一个x
Output
每组输入结束后,从小到大输出集合中的元素,以空格隔开。
Sample Input
2i 2i 24i 1i 1i 2d 10
Sample Output
2 21 2
HINT
用STL的multiset容易解决
#include<iostream>#include<set>using namespace std;int main(){ int n; while(cin>>n&&n!=0) { multiset<int,less<int> > s; multiset<int>::iterator it; while(n--) { char a; cin>>a; if(a=='i') { int b; cin>>b; s.insert(b); } else if(a=='d') { int b; cin>>b; it = s.find(b); s.erase(it); } } for(it=s.begin();it!=s.end();it++) { if(it==s.begin()) cout<<*it; else cout<<" "<<*it; } cout<<endl; } return 0;}
0 0
- Problem B: STL——多重集的插入和删除
- Problem B: STL——多重集的插入和删除
- Problem B: STL——多重集的插入和删除
- OJ:多重集的插入和删除
- Problem B: STL——管道一
- Problem B: STL——管道一
- Problem B: STL——管道一
- Problem B: STL——集合运算
- B-树的插入和删除
- B+树的插入和删除
- B树的插入和删除
- B树 的搜索、插入和删除
- B树的定义、插入和删除
- B树的插入和删除
- B树的插入和删除
- B+树的插入和删除
- 数据结构—Problem B: 删除区间内的元素(线性表)
- 数据结构——B-树的查找和插入
- Jenkins进阶系列之——11修改Jenkins用户的密码
- android studio 查看模拟器或者手机sql数据库
- Jenkins进阶系列之——12详解Jenkins节点配置
- 最短路径(邻接矩阵)-Dijkstra算法
- spark 运行问题总结
- Problem B: STL——多重集的插入和删除
- LintCode 44 最小子数组
- Jenkins进阶系列之——13修改Jenkins权限控制
- 最大权闭合图
- 里氏转换
- 字符串的综合使用
- Jenkins进阶系列之——14配置Jenkins用户和权限
- 【干货】Python使用matplotlib实现数据可视化
- laravel 使用snappy生成pdf文件或生成图片