Set代码
2023-09-14 09:08:54 时间
现有一整数集(允许有重复元素),初始为空。我们定义如下操作:
add x 把 x 加入集合
del x 把集合中所有与 x 相等的元素删除
ask x 对集合中元素x的情况询问
对每种操作,我们要求进行如下输出。
add 输出操作后集合中 x 的个数
del 输出操作前集合中 x 的个数
ask 先输出 0 或 1 表示 x 是否曾被加入集合(0表示不曾加入),再输出当前集合中 x 的个数,中间用空格格开。
输入格式
第一行是一个整数 n,表示命令数。0≤n≤100000。后面 nn 行命令,如 Description 中所述。
输出格式
共 n 行,每行按要求输出。
样例输入
7
add 1
add 1
ask 1
ask 2
del 2
del 1
ask 1
样例输出
1
2
1 2
0 0
0
2
1 0
#include<iostream>
#include<set>
#include<iterator>
using namespace std;
int main()
{
int n;
cin>>n;
char command[4];
multiset<int>mset;
set<int>mm;
multiset<int>::iterator it;
int num;
for (int i = 0; i < n; i++)
{
cin>>command>>num;
switch (command[1])
{
case 'd':
mset.insert(num);
mm.insert(num);
cout<<mset.count(num)<<endl;
break;
case 'e':
cout<<mset.count(num)<<endl;
mset.erase(num);
break;
case 's':
//find(key);//查找键key是否存在,若存在,返回该键的元素的迭代器;若不存在,返回set.end();
if (mm.find(num)==mm.end())
{
cout<<"0 0"<<endl;
}else
{
cout<<"1 "<<mset.count(num)<<endl;
}
break;
default:
break;
}
}
}
相关文章
- 「后端小伙伴来学前端了」Vue中 this.$set的用法 | 可用于修改对象中数组的某一个对象、 可用于更新数据到视图
- js中settimeout和setInterval区别_JavaScript set
- 【C++】map 和 set
- 使用红黑树模拟实现map和set
- ORA-29324: SET COMPATIBILITY release string format is wrong ORACLE 报错 故障修复 远程处理
- ORA-30370: set operators are not supported in this context ORACLE 报错 故障修复 远程处理
- ORA-31523: could not find change source string for CDC change set string ORACLE 报错 故障修复 远程处理
- ORA-39914: Index string.string in tablespace string points to subpartition string of table string.string in tablespace string outside of transportable set. ORACLE 报错 故障修复 远程处理
- ORA-47391: attempt to set Factor string violates Rule Set string ORACLE 报错 故障修复 远程处理
- MySQL Error number: 4161; Symbol: ER_INSTALL_COMPONENT_SET_UNUSED_VALUE; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-55712: XA transactions on RAC are not supported with GLOBAL_TXN_PROCESSES set to 0 ORACLE 报错 故障修复 远程处理
- oracle update set select from 关联更新详解数据库
- java中 set,list,array互转详解编程语言
- MySQL Variables character_set_server 数据库 参数变量解释及正确配置使用
- 命令的使用探索Linux中Set命令的神秘面纱(linux中set)
- MySQL 中SET的用法及其重要性(mysql中的set)
- 轻松获取Redis Set(获取redis set)
- 探究Redis的SET命令的功能与用法(查看redis命令set)
- 红色随机Redis 的Set类型(set 随机 redis)
- 如何有效使用Set结构删除Redis中的数据(set删除redis)
- 深入浅出Redis集群与SET集合(redis集群set集合)
- 优化优化Redis集合Set的性能(redis集合set性能)
- Oracle中掌握SET语句让你如虎添翼(oracle中set语句)
- 使用Redis Set存储数据(redis里set方法)
- 设置Oracle数据库的时间一步一步操作(oracle set时间)