upper_bound初探

#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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值