帮忙看一下错在哪儿了
问题描述:-1为输入截至,依次输出每组的最大和最小体积所对应的名字。#include <stdio.h>
#include <stdlib.h>
typedef struct student{
int length;
int width;
int height;
int volume;
char name[9];
}student;
typedef struct result{
char *max[9];
char *min[9];
}result;
int main(){
int n;
int i,j=0;
int max_flag,min_flag;
scanf("%d",&n);
student stu[9];
result res[9];
while(n!=-1)
{
for(i = 0 ; i < n ; i ++)
{
scanf("%d%d%d%s",&stu[i].length,&stu[i].width,&stu[i].height,stu[i].name);
stu[i].volume = stu[i].length*stu[i].width*stu[i].height;
}
int max = stu[0].volume;
int min = stu[0].volume;
for(i = 0 ; i < n ; i++)
{
if(stu[i].volume >= max)
{
max = stu[i].volume;
max_flag = i;
}
}
for(i = 0 ; i < n ; i++)
{
if(stu[i].volume <= min)
{
min = stu[i].volume;
min_flag = i;
}
}
*res[j].max = stu[max_flag].name;
*res[j].min = stu[min_flag].name;
//printf("%s took clay from %s\n",*res[j].max,*res[j].min);
scanf("%d",&n);
j++;
}
for(i = 0 ; i <= j ; i++)
{
printf("%s took clay from %s\n",*res[i].max,*res[i].min);
}
return 0;
}
程序结果:
3
10 10 2 jill
5 3 10 will
5 5 10 bill
4
2 4 10 cam
4 3 7 sam
8 11 1 graham
6 2 7 pam
-1
graham took clay from sam
graham took clay from cam
预设结果:
3
10 10 2 Jill
5 3 10 Will
5 5 10 Bill
4
2 4 10 Cam
4 3 7 Sam
8 11 1 Graham
6 2 7 Pam
-1
Bill took clay from Will.
Graham took clay from Cam.
怎么回事啊,求大神指导!