set可以重载原有的比较方式,同样适用于find和erase
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 100005;
int m, k;
struct cmp
{
//重载比较方式
// a是原有的数据
bool operator ()(const int &a,const int &b) const
{
if (abs(a-b)<=10) return false;
else return a<b ;//如果ok就按小的排序
}
};
set<int, cmp>s;
void show()
{
for (set<int, cmp>::iterator it = s.begin(); it != s.end(); it++)
{
cout << *it << endl;
}
}
int main()
{
s.insert(1);
s.insert(15);
show();
// insert erase find会删除/查找在 规则之内的数字
if (s.find(202) != s.end())
cout <<1;
}