2890. 询问队员身高

10175102260

Python 3

text=int(input())
for i in range(text):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b = list(map(int, input().split()))
    c=sorted(a,reverse=True)
    d=[]
    e=[]
    for i in b:
        d.append(c[i-1])
    for i in d:
        e.append(a.index(i)+1)
    x=" ".join(str(i) for i in e)
    print(x)
Suzuki_Yuuta
#include <iostream>
#include <algorithm>
using namespace std;

struct member {
    int num;
    int height;
};

bool cmp(const member& a, const member& b)
{
    return (a.height > b.height);
}

void solve()
{
    int memberNum, askNum;
    cin >> memberNum >> askNum;
    member* data = new member[memberNum];
    for (int i = 0; i < memberNum; i++) {
        int temp; cin >> temp;
        data[i].num = i + 1; data[i].height = temp;
    }
    sort(data, data + memberNum, cmp);
    int* ask = new int[askNum];
    for (int i = 0; i < askNum; i++) {
        int temp; cin >> temp;
        ask[i] = temp;
    }
    for (int i = 0; i < askNum; i++) {
        cout << data[ask[i] - 1].num << ((i + 1 == askNum) ? "\n" : " ");
    }
}
Saitama

include

using namespace std;
typedef struct team{int n;int h;}team;
bool cmp(const team &a,const team &b)
{
return a.h>b.h;
}
int main()
{
int T;
cin>>T;
for(int step=0;step>n>>m;
vector a(n);
for(int i=0;i>a[i].h;
a[i].n=i+1;
}
int b[m];
for(int i=0;i>b[i];
}
sort(a.begin(),a.end(),cmp);
for(int i=0;i<m;i++)
{
cout<<a[b[i]-1].n<<’ ‘;
}
cout<<endl;
}
return 0;
}

Li Dao

排序

include

using namespace std;
int T,n,m;
struct People
{
int num,hight;
};
vector V;
int cmp(const People& aa,const People& bb)
{
return aa.hight>bb.hight;
}
int main()
{
cin>>T;
for(int step=0;step>n>>m;
V.clear();
for(int i=1;i<=n;i++)
{
int xx;
cin>>xx;
V.push_back((People){i,xx});
}
sort(V.begin(),V.end(),cmp);
int ff=1;
for(int i=1;i<=m;i++)
{
int xx;
cin>>xx;
if(ff) ff=0; else cout<<’ ‘;
cout<<V[xx-1].num;
}
cout<<endl;
}
return 0;
}

你当前正在回复 博客/题目
存在问题!