zoukankan      html  css  js  c++  java
  • 去重,lower_bound(),upper_bound()

    bool cmp(int a,int b)
    {
        return a<b;
    }
    int main()
    {
        int a[10]={2,7,1,4,4,6};
        sort(a,a+6,cmp);        // 去重之前先排序
        int m=unique(a,a+6)-a; // 去重
        cout<<m<<endl;        // 输出去重之后的长度
        for(int i=0;i<m;i++)
            cout<<a[i]<<' '; // 输出去重之后的数
        cout<<endl;
        int tem=upper_bound(a,a+6,4)-a;
        //按从小到大 4 最多能插入数组 a 的哪个位置
        int p=lower_bound(a,a+6,4)-a;
        //按从小到大,4最少能插入数组 a  的哪个位置
        cout<<tem<<endl;
        cout<<p<<endl;
    }
     
    输出
    5
    1 2 4 6 7
    3 
    2
  • 相关阅读:
    Java的特性和优势
    MyBatis
    SpringBoot简介
    Liunx
    MySql简介与入门
    Volatile
    MySQL简介
    Redis
    Spring IoC
    什么是springboot
  • 原文地址:https://www.cnblogs.com/jk17211764/p/9677391.html
Copyright © 2011-2022 走看看