OJ:多重集的插入和删除
来源:互联网 发布:影子网络怎么进入 编辑:程序博客网 时间:2024/04/30 15:13
Description给你一个集合,一开始集合是空集,然后进行若干操作,最后你要从小到大输出集合中的元素,以空格隔开。(集合中可能会有相同元素)Input一共有若干输入数据,开头一个n(n<=20),n=0代表输入结束。然后有n行,每行有2种形式:“i x”,x是一个整数,代表向集合中插入元素x“d x”,x是一个整数,代表删除一个xOutput每组输入结束后,从小到大输出集合中的元素,以空格隔开。Sample Input2 i 2 i 2 4 i 1 i 1 i 2 d 1 0Sample Output2 2 1 2
#include <iostream>
#include <set>using namespace std;int main(){ int n,x,y,m; char c; multiset<int> a; multiset<int>::iterator p; while(cin>>n) { m=0; if(n==0) return 0; for(int i=0;i<n;i++) { cin>>c; if(c=='i') { cin>>x; a.insert(x); } if(c=='d') { cin>>y; m++; } } if(!a.empty()) { if(m!=0) { while(m--) { for(p=a.begin();p!=a.end();++p) { if(*p==y) {a.erase(p); break;} } } } } if(!a.empty()) { for(p=a.begin();p!=a.end();++p) { if(p==a.begin()) cout<<*p; else cout<<" "<<*p; } cout<<endl; } a.clear(); }}
0 0
- OJ:多重集的插入和删除
- Problem B: STL——多重集的插入和删除
- Problem B: STL——多重集的插入和删除
- Problem B: STL——多重集的插入和删除
- 数据的插入和删除
- 单链表的插入和删除
- 单链表的插入和删除
- BST的插入和删除
- 红黑树的插入和删除
- 容器的插入和删除
- 二叉排序树的插入和删除
- 单链表的插入和删除
- RecyclerView的插入和删除
- 单链表的插入和删除
- 单链表的插入和删除
- RecyclerView的插入和删除
- 红黑树的插入和删除
- 南邮 OJ 1014 数据的插入与删除
- springmvc validator
- storm 连kafka报错
- 二叉树
- VC++ CTabCtrl控件自定义宏使用例子
- as中生成jniLibs目录
- OJ:多重集的插入和删除
- HTTP在.NET中的一些应用和解析
- Tensorflow的Protocol Buffers3编程(一)
- 根据SVN距给定时间之后提交的文件进行增量部署Java工具类
- 每天一个Linux命令(34):du命令
- 将DataTable转换成CSV文件
- Linux学习笔记——例说makefile 增加宏定义
- HDU 4287 Intelligent IME hash
- Android并发编程之图文解析volatile关键字