Loading

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位置第一个大于或等于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

 

posted @ 2019-05-22 22:50  注销111  阅读(237)  评论(0编辑  收藏  举报