unique,lower_bound,stable_sort

unique (a + 1, a + n + 1) is actually a pseudo-deduplication Deduplication, the repeating elements are moved to the back of the array, the first array would typically be sorted, the end return address

lower_bound (first, last, x) returns the x position of insertion in the original series of

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[1000];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    stable_sort(a+1,a+n+1);
    ***************************
    unique(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    printf("%d ",a[i]);
    printf("\n");
    int low=unique(a+1,a+n+1)-a-1;
    for(int i=1;i<=low;i++)
    {
        printf("%d ",a[i]);
    }
    ****************************
    int b;
    printf("\n");
    scanf("%d",&b);
    int val=lower_bound(a+1,a+n+1,b)-a;
    printf("%d ",val);
/*
in:
6
2 5 1 3 5 1
9

out:
1 2 3 5 5 5
1 2 3 5
9
7
*/

}
Published 20 original articles · won praise 1 · views 6321

Guess you like

Origin blog.csdn.net/yichengchangan/article/details/73613036