求助大佬们!runtime error
查看原帖
求助大佬们!runtime error
99244
我是大帅比ZED楼主2022/11/3 11:48

为啥我的代码会runtime error呀 求助orz!!!

#include <stdio.h>
#include <malloc.h>//动态分配空间
#include <math.h>//abs
using namespace std;

struct Student
{
	int Chinese, Math, English;
	char name[9];//9+12=21
};

int sum[1001] = {0};//不超过1000个学生
struct Student * p;

int main (void)
{
	int people;//人数
	scanf("%d", &people);
	
	p = (struct Student *)malloc(people * 21);
	for (int i=0; i<people; i++)
	{
		scanf("%s%d%d%d", p[i].name, &p[i].Chinese, &p[i].Math, &p[i].English);
		sum[i] = p[i].Chinese + p[i].Math + p[i].English;
	}
	
	for (int i=0; i<people-1; i++)//比到倒数第二个人即可
	{
		for (int j=i+1; j<people; j++)
		{
			if (abs(p[i].Chinese - p[j].Chinese) <= 5
				&& abs(p[i].Math - p[j].Math) <= 5
				&& abs(p[i].English - p[j].English) <= 5
				&& abs(sum[i] - sum[j]) <= 10)
				printf("%s %s\n",p[i].name, p[j].name);
		}
	}
	
	return 0;
}
2022/11/3 11:48
加载中...