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";
}
posted @ 2025-06-21 20:41  Fire_poetry  阅读(6)  评论(0)    收藏  举报