lower_bound() + upper_bound()

#include <bits/stdc++.h>
using namespace std;
int num[8]={4,10,11,30,69,70,96,100};
int main()
{
    int pos1=lower_bound(num,num+8,11)-num;//0~7之間>=11的數的位置
    int pos2=upper_bound(num,num+8,11)-num;//>11的數的位置
    cout<<pos1<<" "<<pos2<<endl;
}
//結果爲: 2 3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章