您当前的位置: 首页 >  c++

小天才才

暂无认证

  • 0浏览

    0关注

    168博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

CCF小白刷题之路---201909-4 推荐系统(C/C++ 100分)

小天才才 发布时间:2021-02-17 17:45:44 ,浏览量:0

一、题目描述

在这里插入图片描述 在这里插入图片描述在这里插入图片描述

二、代码实现
#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            
关注
打赏
1658396332
查看更多评论
1.1299s