4 条题解
-
0
#include <iostream> #include <vector> #include <algorithm> // 定义点的结构体 struct Point { int x; int y; }; // 自定义比较函数 bool compare(const Point& a, const Point& b) { if (a.x != b.x) { return a.x < b.x; // 按照横坐标从小到大排序 } return a.y > b.y; // 横坐标相等时,按照纵坐标从大到小排序 } int main() { freopen("point.in","r", stdin); freopen("point.out","w", stdout); int n; std::cin >> n; std::vector<Point> points(n); for (int i = 0; i < n; ++i) { std::cin >> points[i].x >> points[i].y; } // 使用自定义比较函数进行排序 std::sort(points.begin(), points.end(), compare); // 输出排序后的结果 for (const auto& point : points) { std::cout << point.x << " " << point.y << std::endl; } return 0; }
-
0
#include <bits/stdc++.h> using namespace std; struct node{ int x, y; }; bool cmp(node A, node B){ if(A.x != B.x) return A.x < B.x; else return A.y > B.y; } node T[1010]; int main(){ freopen("point.in","r",stdin); freopen("point.out","w",stdout); int n; cin>>n; for (int i = 1; i <= n; i ++){ int a, b; cin >> a >> b; T[i] = {a,b}; } sort(T+1,T+1+n,cmp); for (int i = 1; i <= n; i ++){ cout << T[i].x << " " << T[i].y << endl; } return 0; }
-
0
#include <bits/stdc++.h> using namespace std; struct node{ int x, y; }; bool cmp(node A, node B){ if(A.x != B.x) return A.x < B.x; else return A.y > B.y; } node T[1010]; int main(){ freopen("point.in","r",stdin); freopen("point.out","w",stdout); int n; cin>>n; for (int i = 1; i <= n; i ++){ int a, b; cin >> a >> b; T[i] = {a,b}; } sort(T+1,T+1+n,cmp); for (int i = 1; i <= n; i ++){ cout << T[i].x << " " << T[i].y << endl; } return 0; }
-
0
#include <bits/stdc++.h> using namespace std; struct node{ int x, y; }; bool cmp(node A, node B){ if(A.x != B.x) return A.x < B.x; else return A.y > B.y; } node T[1010]; int main(){ freopen("point.in","r",stdin); freopen("point.out","w",stdout); int n; cin>>n; for (int i = 1; i <= n; i ++){ int a, b; cin >> a >> b; T[i] = {a,b}; } sort(T+1,T+1+n,cmp); for (int i = 1; i <= n; i ++){ cout << T[i].x << " " << T[i].y << endl; } return 0; }
- 1
信息
- ID
- 150
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 77
- 已通过
- 27
- 上传者