Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- struct point {
- int x, y;
- string name;
- double dist();
- };
- double point::dist() {
- return sqrt((double)(x * x + y * y));
- }
- void sort(point* y, int n) {
- point temp;
- int i, j;
- for (i = 0; i < n - 1; i++) {
- for (j = n - 1; j > i; j--) {
- if (y[j].dist() < y[j - 1].dist()) {
- temp = y[j];
- y[j] = y[j - 1];
- y[j - 1] = temp;
- }
- if ((y[j].dist() == y[j - 1].dist()) && (y[j].name < y[j - 1].name)) {
- temp = y[j];
- y[j] = y[j - 1];
- y[j - 1] = temp;
- }
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- point* t = new point[n];
- for (int i = 0; i < n; i++) {
- cin >> t[i].x >> t[i].y >> t[i].name;
- }
- sort(t, n);
- for (int i = 0; i < n; i++) {
- cout << t[i].name << " " << t[i].x << " " << t[i].y << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement