关于set/map存结构体
重载运算符写完整
这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
return cnt > t.cnt;
}
};
set<node> tong;
int main()
{
tong.insert({1, 5});
tong.insert({1, 6});
cout << tong.size();
return 0;
}这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
if (cnt == t.cnt) return id > t.id;
return cnt > t.cnt;
}
};
set<node> tong;
int main()
{
tong.insert({1, 5});
tong.insert({1, 6});
cout << tong.size();
return 0;
}这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
return cnt > t.cnt;
}
};
map<node, int> tong;
int main()
{
tong[{1, 5}] = 1;
cout << tong[{1, 6}];
return 0;
}这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
if (cnt == t.cnt) return id > t.id;
return cnt > t.cnt;
}
};
map<node, int> tong;
int main()
{
tong[{1, 5}] = 1;
cout << tong[{1, 6}];
return 0;
}