P5741 【深基7.例10】旗鼓相当的对手 加强版

题目传送门

#include <bits/stdc++.h>

using namespace std;

const int N = 1100;
struct Student {
    string name;
    int x;
    int y;
    int z;
    int sum;
} a[N];
int n;

void check(Student p, Student q) {
    if (abs(p.x - q.x) <= 5 && abs(p.y - q.y) <= 5 && abs(p.z - q.z) <= 5 &&
        abs(p.sum - q.sum) <= 10) {
        cout << p.name << " " << q.name << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].name >> a[i].x >> a[i].y >> a[i].z;
        a[i].sum = a[i].x + a[i].y + a[i].z;
    }

    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            check(a[i], a[j]);
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15575654.html