结构体用于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>, ...
随机推荐
- Ansible :一个配置管理和IT自动化工具
编译文章:LCTT https://linux.cn/article-4215-1.html 译者: felixonmars 文章地址:https://linux.cn/article-4215-1 ...
- 有一种感动叫ACM(记WJMZBMR在成都赛区开幕式上的讲话)
各位选手,各位教练,大家好,我是来自清华大学交叉信息学院的陈立杰,今天很荣幸站在这里代表全体参赛选手发言.对于我来说,这是我第一次正式参加ACM的比赛.不过我跟ACM之间的缘分,大概在很早的时候就已经 ...
- Metro UI(Win 8风格)页面设计小记
一.Metro风格菜单——简单 HTML <div class="pagina "> <div class="linha"> <d ...
- 权威第三方报告——获取IT产品竞争力信息的主要途径,类似你买电脑前上的xx论坛看实力评估
Gartner is known for its huge influence on purchasing as well as an unequaled events business. Forre ...
- matlab report generator
Programmatic report creation Create report content Mlreportgen.dom.Document.append Mlreportgen.dom.P ...
- cisco VPN
配置实例:公司在北京而分公司在上海,如果租用光纤业务费用会比较高,另外安全性也没有保证,特别是对内网的访问方面.我们要在总公司和分公司之间建立有效的VPN连接.具体网络拓扑如图1所示.北京路由器名为R ...
- HookIAT的启动程序
// 启动程序.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #include &l ...
- MySQL为数据表的指定字段插入数据
username not null 没有默认值/有默认值 insert不插入username字段 均不报错 2014年07月23日21:05 百科369 MySQL为数据表的指定字段插入数据 ...
- DML数据操作语言练习
--创建表T_HQ_BM2 --create table t_hq_bm2 as select * from t_hq_bm; commit; --添加行内容 --insert into t_hq_b ...
- exe转msi
1.起因 由于域推送只支持msi安装包,而很多常用的工具比如Adobe Flash Player.exe.SilverLight.exe都是exe格式的,于是引出要将exe转成silent msi的工 ...