1 solutions

  • 0
    @ 2025-3-3 16:25:45

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    map <int,int> m; 
    int a[100010];
    int main(){
        int n,i;
        scanf("%d",&n);
        //求每个数字出现的次数 
        for(i = 1;i <= n;i++){
            cin>>a[i];
            //如果x在map中没有出现过
            if(m.count(a[i]) == 0){
                m[a[i]] = 1;
            }else{
                m[a[i]]++;
            }
        }
          
        int c = 1,t;
        //修正名次
        for(map<int,int>::reverse_iterator j = m.rbegin();j != m.rend();j++){
            t = j->second;
            m[j->first] = c;
            c = c + t;
        }
          
        //输出结果
        for(i = 1;i <= n;i++){
    //        cout<<m[a[i]]<<endl;
            printf("%d\n",m[a[i]]);
        } 
          
    }
    
    
    • 1

    Information

    ID
    10064
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By