求救,c语言,自测1000个数据输入后答案是一样的,但全部wa
查看原帖
求救,c语言,自测1000个数据输入后答案是一样的,但全部wa
1121115
scnucjh6楼主2023/10/26 19:38
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct p {
	char name[8];
	int c;
	int m;
	int e;
};

struct q {
	char a[8];
	char b[8];
};


int main()
{
	setvbuf(stdout, NULL, _IOFBF, 60024000);
	int n = 0;
	scanf("%d", &n);
	int aa = 1000*(1000-1)/2;
    struct p *list = (struct p*)malloc(1001 * sizeof(struct p));
    struct q *nn = (struct q*)malloc(aa * sizeof(struct q));
	int cnm = 0;
	int k = 0;
	while (k < n) {
		scanf("%s", &list[k].name);
		scanf("%d", &list[k].c);
		scanf("%d", &list[k].m);
		scanf("%d", &list[k].e);
		k++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			if (abs(list[i].c-list[j].c)<=5 && abs(list[i].m-list[j].m)<=5 && abs(list[i].e-list[j].e)<=5 && abs(list[i].c+list[i].m+list[i].e-list[j].c-list[j].m-list[j].e)<=10) {
				strcpy(nn[cnm].a, list[i].name);
				strcpy(nn[cnm].b, list[j].name);
				cnm++;
			}
		}
	}
	int ans = 0; 
	while (cnm--) {
		printf("%s  %s\n", nn[ans].a, nn[ans].b);
		ans++;
	}
	free(nn);
	free(list);
}
2023/10/26 19:38
加载中...