#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
bool cmp(const int &a,const int &b)
{
return a>b;//jiangxu
}
int main()
{ int a[20]={10,20,30,30,30,40,50};
int b[20]={50,40,30,30,30,20,10};
int c[20]={1,1,1,1,1,1,1};
//sort(b,b+7);
int te=upper_bound(c,c+7,1)-c;
int tew=lower_bound(c,c+7,1)-c;
cout<<te<<tew<<endl;
int u=upper_bound(a,a+7,30,cmp)-a;
int l=lower_bound(a,a+7,30,cmp)-a;
cout<<u<<"第一个大于30的坐标"<<endl;
cout<<l<<"第一个不小于30的坐标"<<endl;
int s=upper_bound(b,b+7,40,cmp)-b;//第一个小于40的;
int y=lower_bound(b,b+7,40,cmp)-b;//第一个小于等于40的;
cout<<s<<endl;
cout<<y<<endl;
//upper_bound和lower_bound各有两个定义,一个有比较函数,一个没有;
//1 对于升序(非降序,数字项都相同)排列的函数,可以不写比较函数;
//对于降序的函数,我们应该用把cmp变成降序的;
//那么他会返回
return 0;
}
upper_bound初探
最新推荐文章于 2024-06-16 12:31:02 发布