You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
743 B
35 lines
743 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
vector<int> f = {1, 2, 3, 4, 5, 5, 5, 6, 6, 7};
|
||
|
|
||
|
void print() {
|
||
|
for (int i = 0; i < f.size(); i++) printf("%d ", f[i]);
|
||
|
puts("");
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
//要使用二分,必须先排序
|
||
|
sort(f.begin(), f.end());
|
||
|
print();
|
||
|
|
||
|
cout << lower_bound(f.begin(), f.end(), 5) - f.begin() << endl;
|
||
|
cout << upper_bound(f.begin(), f.end(), 5) - f.begin() << endl;
|
||
|
//打印
|
||
|
print();
|
||
|
|
||
|
// // 插入值
|
||
|
// int x = 3;
|
||
|
// f.insert(lower_bound(f.begin(), f.end(), x), x);
|
||
|
// //打印
|
||
|
// print();
|
||
|
|
||
|
// // 删除值
|
||
|
// x = 2
|
||
|
// f.erase(lower_bound(f.begin(), f.end(), x));
|
||
|
// //打印
|
||
|
// print();
|
||
|
|
||
|
return 0;
|
||
|
}
|