stl实现离散化

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#define FOR(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
vector<int>v;
int a[23333];
int n;
inline int read(){
	char c;while(c=getchar(),c==' '||c=='\n');int data=c-48;
	while(c=getchar(),c>='0'&&c<='9')data=(data<<1)+(data<<3)+c-48;return data;
}
int main(){
	scanf("%d",&n);
	FOR(i,1,n)v.push_back(a[i]=read());
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	FOR(i,1,n)printf("%d ",lower_bound(v.begin(),v.end(),a[i])-v.begin());
	return 0;
}

  

posted @ 2017-11-05 19:47  Stump  阅读(479)  评论(0编辑  收藏  举报