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)
Python 3
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;
}
排序
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;
}