【1129】recommendation (25分)【set 运算符重载】

网友投稿 571 2022-10-31

【1129】recommendation (25分)【set 运算符重载】

【1129】recommendation  (25分)【set 运算符重载】

#include#include#include#include#include#include #include#include#include #includeusing namespace std; //符号重载的node结构体作为set的元素自动排序,每次推荐set中的前k项//book[num]标记num出现的次数//注意先不处理输入的数字,根据之前的数据输出前K再存刚才新数据int book[50001];struct node{ int value,cnt; bool operator<(const node &a)const{ return (cnt!=a-t)?cnt>a-t:values; for(int i=0;ivalue); tempCnt++; } printf("\n"); } struct node a={num,book[num]}; auto it=s.find(a);//返回a在set中对应的指针 if(it!=s.end()) s.erase(it); //如果a结构体存在就先删除 book[num]++; struct node b={num,book[num]}; //重新插入新的num结构体 s.insert(b); } system("pause"); return 0; }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【1127】ZigZagging on a Tree (30分)【中后序建树 层次】
下一篇:Python程序,用于嗅探未加密的探测请求并将其记录到MySQL
相关文章

 发表评论

暂时没有评论,来抢沙发吧~