#include using namespace std; vector 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; }