结构体用于map,set时要重载运算符<
#include<iostream>
#include<set>
using namespace std;
struct P
{
int entry;
int time;
bool operator<(const P &b)const {
return (this->entry<b.entry);
} };
int main()
{
while(!cin.eof())
{
int n;
cin>>n;
set<P> s;
P tmp; for(int i = 0;i<n;i++)
{
tmp.time = 1;
cin>>tmp.entry;
if(s.find(tmp)==s.end())s.insert(tmp);
else
{
set<P>::iterator it; it = s.find(tmp);
tmp=*it;
tmp.time++;
s.erase(it);
s.insert(tmp);
}
}
set<P>::iterator itr;
for(itr = s.begin();itr!=s.end()&&!cin.eof();itr++)
if(itr->time % 2)
cout<<itr->entry<<endl;
}
}
举例: #include <map>
#include <iostream>
#include <string> using namespace std; //学生信息
typedef struct tagStudentInfo
{
int nID;
string strName;
bool operator <(const tagStudentInfo &A) const
{
if (nID < A.nID) return true; //先比较nID
if (nID == A.nID) return strName.compare(A.strName) < ; //nID相同时,再比较strName
return false;
} }StudentInfo,*pstudentInfo;
结构体用于map,set时要重载运算符<的更多相关文章
- 结构体作为map的key或放入set中,需要重载<运算符
结构体作为map的key或放入set中,需要重载<运算符,如下: typedef struct tagRoadKey{ int m_i32Type; int m_i32Scale; ...
- GO学习-(38) Go语言结构体转map[string]interface{}的若干方法
结构体转map[string]interface{}的若干方法 本文介绍了Go语言中将结构体转成map[string]interface{}时你需要了解的"坑",也有你需要知道的若 ...
- Golang操作结构体、Map转化为JSON
结构体生成Json package main import ( "encoding/json" "fmt" ) type IT struct { Company ...
- 初次见识结构体与map的区别
题目 http://vjudge.net/contest/view.action?cid=51142#problem/G 自己做的结构体 #include <iostream>#incl ...
- Go 结构体和map等数据结构转json字符串
Go语言中使用json包中的 Marshal() 函数将数据结构转成json字符串,源代码: func Marshal(v interface{}) ([]byte, error) { e := ne ...
- C++ 结构体、模板、类、重载初使用
目的:需要几个缓存用的数组900*750 首先定义一个模板<参数数据类型,参数1,参数2> 定义一个class类 名字自己取ap_uint0 下面是公用的数组模板[lrow][lcol] ...
- C++中,用类和重载运算符写高精模板
先放代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; s ...
- 用set、map等存储自定义结构体时容器内部判别各元素是否相同的注意事项
STL作为通用模板极大地方便了C++使用者的编程,因为它可以存储任意数据类型的元素 如果我们想用set与map来存储自定义结构体时,如下 struct pp { double xx; double y ...
- STL map、set中key为结构体的用法
下面是map定义的结构: // TEMPLATE CLASS map template<class _Kty, class _Ty, class _Pr = less<_Kty>, ...
随机推荐
- 网页html结构右侧栏固定,左侧自适应大小。
最近写了一个项目,写页面的结构,html树形结构是有header,container,footer部分,其中container部分是右侧栏是固定宽度,左侧是自适应宽度与屏幕高度. 第一次写的博客文章是 ...
- 创建PO
FORM FRM_CREATE_PO USING P_POSNR CHANGING P_EBELN. DATA: LV_VENDOR TYPE LIFNR, LV_ITEM TYPE EBELP, L ...
- css3 keyframes animation
html,body,div,span,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,address,big,cite,code,del,em,font,img ...
- httpClient 4.x post get方法
public static String doPost(String url, String encoding, String contentType, String sendData) throws ...
- git 将本地项目添加到远程
git init git add README.md git commit -m "first commit" git remote add origin git@github.c ...
- C#图书资源【更新中...】喜欢的就转存吧
百度分享暂时取消了,需要的朋友可以直接关注我,我发给你. 重点篇 1.C#与.NET3.5高级程序设计 2.C#与.NET3.5高级程序设计.rar 3.Effective_C#_中文版_改善C#程序 ...
- 使用System.Timers.Timer类实现程序定时执行
使用System.Timers.Timer类实现程序定时执行 在C#里关于定时器类有3个:System.Windows.Forms.Timer类.System.Threading.Timer类和Sys ...
- 最新电Call记录统计-full hash join用法
declare @time datetime set @time='2016-07-01' --最新的电Call记录统计查询--SELECT t.zuoxi1,t.PhoneCount,t.Phone ...
- php 加密解密字符串
/********************************************************************* 函数名称:encrypt 函数作用:加密解密字符串 使用方 ...
- dedecms5.7安装百度(ueditor)编辑器的方法
第一步:下载相对应编辑器的版本 第二步:修改inc_func_funcAdmin.php文件 打开include下的inc文件夹内的inc_func_funcAdmin.php找到184行,贴入以下代 ...