C++ lower_bound

代码

#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {

    float cdf[5] = { 0.13,0.23,0.33,0.43,0.53 };
    // 从数组的begin位置到end-1位置第一个大于或等于num的数字,不存在则返回end
    cout << *(lower_bound(cdf, cdf + 4, 0.32)) << endl;
    cout << *(lower_bound(cdf, cdf + 4, 0.33)) << endl;
    cout << *(lower_bound(cdf, cdf + 4, 0.34)) << endl;
    cout << *(lower_bound(cdf, cdf + 4, 0.43)) << endl;
    cout << *(lower_bound(cdf, cdf + 4, 0.44)) << endl;

    return 0;
}

输出

0.33
0.33
0.43
0.43
0.53

猜你喜欢

转载自www.cnblogs.com/heben/p/10909101.html