离散化

文如其名

留下板子可日后复习

#include <bits/stdc++.h>
using namespace std;
const int maxn=100;
int a[maxn],tp[maxn],res[maxn],n;
map<int,int> mp;
int main(){
    freopen("100.in","r",stdin);
    freopen("100.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];    
    for(int i=1;i<=n;i++) tp[i]=a[i];
    sort(tp+1,tp+1+n);
    int m=unique(tp+1,tp+1+n)-(tp+1);
    for(int i=1;i<=m;i++)
       mp[tp[i]]=i;
    for(int i=1;i<=n;i++)
       res[i]=mp[a[i]];
    for(int i=1;i<=n;i++)
       cout<<res[i]<<" ";
    return 0;
}

 

posted @ 2018-08-06 09:10  ASDIC减除  阅读(107)  评论(0编辑  收藏  举报