lower/upper_bound
#include<algorithm>
#include<map>
#include<set>
#include<iostream>
using namespace std;
int a[1000];
set<int> se;
int main()
{
int n=10;
for (int i=1;i<=n;i++)
a[i] = i*i;
auto x = lower_bound(a+1,a+n+1,15);
x --;
cout << *x << "\n";
for (int i=1;i<=n;i++)
se.insert(i*i);
//错误写法
lower_bound(se.begin(),se.end(),15);
//正确写法
auto y = se.lower_bound(15);
cout << *y << "\n";
}

浙公网安备 33010602011771号