upper_bound()与lower_bound()使用方法

来源:互联网 发布:淘宝买家秀裸露店铺 编辑:程序博客网 时间:2024/05/17 17:58
如果会用这两个函数,上次打比赛,我就不会是铜奖,而是银奖了。。。哎。。。平时积累不够

http://blog.sina.com.cn/s/blog_62582b7e0100eyqz.html


upper_bound()与lower_bound()使用方法

 (2009-10-05 11:31:10)
转载
标签: 

杂谈

分类: STL

#include <iostream>
#include <algorithm>//必须包含的头文件
using namespace std;

int main(){
 int point[10] = {1,3,7,7,9};
 int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,7最多能插入数组point的哪个位置
 printf("%d\n",tmp);
 tmp = lower_bound(point, point + 5, 7) - point;////按从小到大,7最少能插入数组point的哪个位置
 printf("%d\n",tmp);
 return 0;
}

output:

4

2

原创粉丝点击