提交时间:2024-08-19 22:09:58

运行 ID: 168065

#include <iostream> using namespace std; struct Pair { int first, second; }; bool compare(Pair p1, Pair p2) { if (p1.first == p2.first) return p1.second < p2.second; return p1.first < p2.first; } int main() { int n; cin >> n; Pair arr[100005]; for (int i = 1; i <= n; i++) { cin >> arr[i].first >> arr[i].second; } sort(arr + 1, arr + n + 1, compare); for (int i = 1; i <= n; i++) { cout << arr[i].first << " " << arr[i].second << "\n"; } return 0; }