题解
2023-11-12 15:03:39
发布于:广东
7阅读
0回复
0点赞
#include <iostream>
#include<algorithm>
using namespace std;
struct names{
string name;
int value;
int id;
}a[1005];
bool comp(names a, names b){
if(a.value != b.value) return a.value > b.value;
else return a.id < b.id;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].name >> a[i].value;
a[i].id = i;
}
sort(a + 1, a + n + 1, comp);
for(int i = 1; i <= n; i++){
cout << a[i].name << ' ' << a[i].value << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个