1 solutions

  • 0
    @ 2023-1-21 16:22:23
    #include<bits/stdc++.h>
    using namespace std;
    /*
    1、对数组降序排序
    2、求每个元素在排序后的数组中第一次出现的位置 
    */
    int a[1010],b[1010],n;
    //比较函数:指定排序规则
    bool cmp(int x,int y){
    	return x > y;
    } 
    int main()
    {
    	cin >> n;
    	for(int i = 1; i <= n; i++){
    		cin >> a[i];
    		b[i] = a[i];
    	}
    	sort(a+1,a+1+n,cmp);
    	//求[i] 在a数组中首次出现的位置
    	for(int i = 1; i <= n; i++){
    		for(int j = 1; j <= n; j++){
    			if(b[i] == a[j]){
    				cout << j << " ";
    				break;
    			}
    		}
    	} 
    	return 0;
    }
    
    
    
    • 1

    Information

    ID
    792
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    10
    Tags
    # Submissions
    3
    Accepted
    3
    Uploaded By