unique(a+1,a+n+1)去重实际上是伪去重,将重复元素都移到了数组后面,一般要将数组先排序,返回尾地址
lower_bound(first,last,x)返回插入x在原数列中的位置
#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
*/
}