AcWing 3376. 成绩排序2
原题链接
简单
作者:
王杜杜
,
2025-01-13 21:39:53
,
所有人可见
,
阅读 2
C++ 代码
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::vector;
typedef struct{
int id;
int grade;
}Grade;
bool cmp(Grade& g1, Grade& g2){
if(g1.grade == g2.grade) return g1.id <= g2.id;
return g1.grade <= g2.grade;
}
int main()
{
int N;
cin >> N;
vector<Grade> vec;
for(int i=0; i<N; i++){
Grade g;
cin >> g.id >> g.grade;
vec.push_back(g);
}
sort(vec.begin(), vec.end(), cmp);
for(auto& elem : vec){
cout << elem.id << ' ' << elem.grade << endl;
}
return 0;
}