笔记
pair常用于两种类型相关联的表示,这往往比struct更省代码
a.first, a,second
代码
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 110;
typedef pair<int, string> PIS;
PIS a[N];
int n;
bool cmp(PIS a, PIS b) {
return a.first > b.first;
}
int main() {
cin>>n;
for(int i = 0; i < n; i++) cin>>a[i].first>>a[i].second;
sort(a, a + n, cmp);
for(int i = 0; i < n; i++) cout<<a[i].second<<endl;
return 0;
}