1082 射击比赛 (20 分)

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
struct s {
    string id;
    int dis;
} num[10010];   // 结构体数组变量开的大一点
bool cmp (s a, s b) {  // 形参中用结构体定义两个结构体变量
    return a.dis < b.dis;
}
int main() {
    int n, x, y;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> num[i].id >> x >> y;
        num[i].dis = x * x + y * y;    // 将其平方加入到结构体数组变量中
    }
    sort(num, num + n, cmp);   // 排序
    cout << num[0].id << ' ' << num[n - 1].id << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Hk456/p/10793644.html