64,649
社区成员
发帖
与我相关
我的任务
分享
struct MyCOORD
{
short X;
short Y;
bool operator == (const MyCOORD &crd) const
{
if (this->X == crd.X && this->Y == crd.Y)
{
return true;
}
return false;
}
bool operator != (const MyCOORD &crd) const
{
return !(*this == crd);
}
bool operator < (const MyCOORD &crd) const
{
if (crd == *this)
{
return false;
}
return this->Y < crd.Y || this->X < crd.X;
}
bool operator > (const MyCOORD &crd) const
{
return !(*this < crd);
}
};
int main() {
set<MyCOORD> test;
test.insert({ 2,2 });
test.insert({ 1,3 });
test.insert({ -1,2 });
test.insert({ 2,2 });
test.insert({ 2,2 });
test.insert({ 2,2 });
set<MyCOORD> test2;
test2.insert({ 1,2 });
test2.insert({ 2,3 });
test2.insert({ -2,2 });
test2.insert({ 2,2 });
test2.insert({ 3,2 });
test2.insert({ 1,2 });
set<MyCOORD> result;
set_intersection(test.begin(),test.end(), test2.begin(),test2.end(),result.begin());
system("pause");
return 0;
}
bool operator < (const MyCOORD &crd) const
{
if (this->Y < crd.Y)
{
return true;
}
else if (this->Y == crd.Y &&this->X < crd.X)
{
return true;
}
return false;
}