Sort - C

public
yeskendir.sultanov Mar 31, 2024 Never 53
Clone
C++ Csort.cpp 32 lines (27 loc) | 656 Bytes
1
#include <bits/stdc++.h>
2
3
using namespace std;
4
5
struct Point {
6
int x, y;
7
};
8
9
double distance(Point A, Point B) {
10
return sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
11
}
12
13
bool cmp(Point A, Point B) {
14
return (distance(A, {0, 0}) < distance(B, {0, 0}));
15
}
16
17
int main() {
18
std::ios_base::sync_with_stdio(false);
19
cin.tie(0);
20
cout.tie(0);
21
int n;
22
cin >> n;
23
Point a[n];
24
for (int i = 0; i < n; ++i) {
25
cin >> a[i].x >> a[i].y;
26
}
27
sort(a + 0, a + n, &cmp);
28
for (int i = 0; i < n; ++i) {
29
cout << a[i].x << " " << a[i].y << endl;
30
}
31
return 0;
32
}
33