Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
134828 why 双关键字排序 C++ 通过 100 406 MS 1032 KB 839 2024-03-02 21:14:05

Tests(5/5):


#include <iostream> #include <vector> #include <algorithm> // 定义一个结构体表示一对整数 struct Pair { int first; int second; }; // 自定义比较函数,按照题目要求进行排序 bool comparePairs(const Pair& p1, const Pair& p2) { if (p1.first == p2.first) { return p1.second < p2.second; } return p1.first < p2.first; } int main() { int n; std::cin >> n; std::vector<Pair> pairs(n); for (int i = 0; i < n; i++) { std::cin >> pairs[i].first >> pairs[i].second; } // 使用自定义的比较函数进行排序 std::sort(pairs.begin(), pairs.end(), comparePairs); // 输出排序后的结果 for (const Pair& p : pairs) { std::cout << p.first << " " << p.second << std::endl; } return 0; }


测评信息: