zoukankan      html  css  js  c++  java
  • unique

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int  main()
     4 {
     5     int a[10]={0,1,5,3,6,9,2,9,10,23};
     6     sort(a,a+10);//先排序
     7     int pos1=upper_bound(a,a+6,3)-a;//大于
     8     int pos2=upper_bound(a+1,a+7,6)-a;//不是a+1
     9     printf("%d %d
    ",pos1,pos2);//4 6(下标)
    10     return 0;
    11 }
    12

    int a[8]={1,2,3,4,5};
    int p=lower_bound(a,a+5,6)-a;
    cout<<p<<endl;//5

    13 

    set<int>s;
    set<int>::iterator it;
    s.insert(3);
    s.insert(2);
    s.insert(1);
    s.insert(5);
    it=s.lower_bound(10);
    cout<<(*it)<<endl;//4(set的大小)

    14 /*
    15 #include <bits/stdc++.h>
    16 using namespace std;
    17 //一般使用前需要对容器进行排序,这样才能实现对整个数组去重。
    18 int  main()
    19 {
    20     int a[10]={0,1,5,5,5,5,0,6,7};
    21     sort(a,a+9);
    22     int ans1=unique(a,a+9)-a;//去掉重复的,整个数组还有几个数 减a,不是a+1
    23     for(int i=0;i<ans1;i++) printf("%d ",a[i]);
    24     printf("
    ");
    25     printf("%d 
    ",ans1);    
    26     0 1 5 6 7
    27     5
    28     return 0;
    29     
    30 }
    31 */
  • 相关阅读:
    vmwear 及docker
    vue相关
    vue demo
    线程的死锁
    让出和守护线程
    join加入线程
    线程的优先级
    线程间的通信
    synchronized关键字的使用
    线程的并发
  • 原文地址:https://www.cnblogs.com/tingtin/p/9439595.html
Copyright © 2011-2022 走看看