题解
2024-01-06 18:17:23
发布于:广东
6阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct weapon
{
string name;
int atk,pri;
};
bool cmp(weapon x,weapon y)
{
if (x.atk!=y.atk)
return x.atk<y.atk;
else if (x.pri!=y.pri)
return x.pri>y.pri;
}
int main()
{
int n,k;
cin >> n >> k;
weapon w[n];
for (int i=0;i<n;i++)
cin >> w[i].name >> w[i].atk >> w[i].pri;
sort(w,w+n,cmp);
for (int i=n-1;i>=n-k;i--)
cout << w[i].name << endl;
return 0;
}
这里空空如也
有帮助,赞一个