#2019120500012-LG 小鱼比可爱

P1428 小鱼比可爱 数组

可以使用结构体,由于数据过小,\(n \leq 100\)也可以单纯使用循环

栈也可以,没试过

//P1428 数组 排序 模拟
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
struct tit{
    int a;
    int score;
};
tit fish[105];
bool cmp(tit x,tit y){
    if(x.score==y.score) return x.a<y.a;
    return x.score<y.score;
} 
int main( ){
    //freopen("ans.in","r",stdin);
    //freopen("ans.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&fish[i].score);
        fish[i].a=i;
    }
    int k[n+5];
    memset(k,0,sizeof(k));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            if(fish[j].score<fish[i].score) k[fish[i].a]++;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",k[i]);
    }
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/liuziwen0224/p/11992397.html