본문 바로가기

C++

upper_bound, lower_bound

#include "pch.h"
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>


using namespace std;


int main() {
	vector<int> arr;
	for (int i = 1; i <= 10; i++)
		arr.push_back(i);

	int target = 5;
	auto a = upper_bound(arr.begin(), arr.end(), target);
	auto b = lower_bound(arr.begin(), arr.end(), target);
	cout << arr[a - arr.begin()] << ' ' << arr[b - arr.begin()];

}