测试过了,但0分,求助大佬
查看原帖
测试过了,但0分,求助大佬
1354168
czq__楼主2024/7/23 07:44
#include<bits/stdc++.h>
using namespace std;
struct student {
	string name;
	int a, b, c, d;
}s[1005];
//输入和计算总分
void input(student& a) {
	cin >> a.name >> a.a >> a.b >> a.c;
	a.d = a.c + a.b + a.a;
}

//判断是否为对手
bool han(student a, student b) {
	if (abs(a.a - b.a) > 5) return false;
	if (abs(a.b - b.b) > 5) return false;
	if (abs(a.b - b.b) > 5) return false;
	if (abs(a.d - b.d) > 10) return false;
	return true;
}

//用于sort按name排序
bool paixu(student a, student b) {
	return a.name < b.name;
}

int main() {
	int n; cin >> n;

	for (int i = 0; i < n; i++)
		input(s[i]);

	sort(s, s + n, paixu);

	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++) {
			if (han(s[i], s[j])) {
				cout << s[i].name << ' ' << s[j].name << endl;
			}
		}
}```
2024/7/23 07:44
加载中...