請問大神這個怎麼解決??謝謝了
代碼如下:
#include<stdio.h>
#include<stdlib.h>
struct student { //xtudent 學籍;
int c; //長
int k; //寬
int g; //高
char name[9]; //姓名
struct stdent *next;
};
typedef struct student student;
int main()
{
int n;
while (scanf("%d", &n))
{
if (n != -1) {
int j;
student *p_head, *p_rail, *p_st;
p_head = (student *)malloc(sizeof(student));
p_rail = p_head;
int lfn[9]; //儲存體積
char *lfnch[10]; //用於儲存要找的名字
for (j = 0; j < n; j++)
{
p_st = (student *)malloc(sizeof(student));
scanf("%d %d %d %s", &(p_st->c), &(p_st->k), &(p_st->g), p_st->name);
p_rail->next = p_st;
p_rail = p_st;
lfn[j] = (p_st->c)*(p_st->k)*(p_st->g); //把體積儲存在數組中;
lfnch[j] = (p_st->name); //分別把名字儲存在數組中;
}
int min = lfn[0], max = lfn[0],pos1,pos2;
for (j = 1; j < n; j++) //找到體積最大最小並標記下標;
{
if (min > lfn[j])
{
min = lfn[j];
pos1 = j;
}
else pos1 = 0;
if (max < lfn[j])
{
max = lfn[j];
pos2 = j;
}
}
printf("%s took clay from %s\n", lfnch[pos2], lfnch[pos1]);
min = 0, max = 0;
}
else
break;
}
return 0;
}
筆誤:
struct student { //xtudent 學籍;
int c; //長
int k; //寬
int g; //高
char name[9]; //姓名
struct student *next;
};
仔細看粗體部分。