一、题目描述
#include
#include
#include
using namespace std;
//商品
struct Good{
int type;
int id;
int score;
};
//删除的商品
struct Del_Good{
int type;
int id;
};
set good;
set del_good;
//运算符重载temp.score;
for(int j=0;j>op_num;
while(op_num--)
{
int op;
cin>>op;
//操作1---添加商品
if(op==1)
{
Good temp;
cin>>temp.type>>temp.id>>temp.score;
good.insert(temp);
}
//操作2---删除商品,统一用结构体存储
else if(op==2)
{
Del_Good temp;
cin>>temp.type>>temp.id;
del_good.insert(temp);
}
else
{
int k,type_k[m];
cin>>k;
for(int i=0;i>type_k[i];
}
vector output[m];
//判断每一个商品是否被删除
for(set::iterator it = good.begin();k>0 && it!=good.end();)
{
if(type_k[(*it).type] > 0)
{
Del_Good temp;
temp.type = (*it).type;
temp.id = (*it).id;
//find找不到返回的是end()
if(del_good.find(temp)!=del_good.end())
{
//这里注意it++要写在括号里面
//erase之后it所在位置为null
//写在外面的话就it++就定位不到下一个了
good.erase(it++);
}
else
{
type_k[(*it).type]--;
k--;
output[(*it).type].push_back((*it).id);
it++;
}
}
else it++;
}
for(int i=0;i0)
{
for(int j=0;j
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?