给个赞吧
查看原帖
给个赞吧
676426
Hp_1919810楼主2022/5/22 17:57

此题思路:结构体+二重循环

My Code:

#include <bits/stdc++.h>//万能头文件
using namespace std;
int n, ans = 0;
struct s{、、结构体
	int c, m, e;
	void read(){
		cin >> c >> m >> e;
	}
};
s a[1001];
bool chk(s x, s y){
	if(abs(x.c - y.c) > 5)
		return false;
	if(abs(x.m - y.m) > 5)
		return false;
	if(abs(x.e - y.e) > 5)
		return false;
	if(abs(x.c - y.c + x.m - y.m + x.e - y.e) > 10)
		return false;
	return true;
}
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		a[i].read();
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			ans += (chk(a[i], a[j]));
	cout << ans << endl;//输出
}
2022/5/22 17:57
加载中...