寄包柜C语言实现错误方便指正

P3613 【深基15.例2】寄包柜

zbj15010210485 @ 2022-03-10 14:26:02

# 寄包柜问题C语言实现错误
```c
# include <stdio.h>
# include <stdlib.h>
typedef struct Node *In;
typedef struct Node{
    int n;// 0/1
    int m;// n个柜子
    int k;// m个格子
    int q;// q个物品
    In Next;
};
typedef In List;
List ReadPoly();
void Attach(int n,int m,int k,int q,In *Prear);
void PrintSearch(In Prear);
int main()
{
  List com;
  com = ReadPoly();
  PrintSearch(com);
  return 0;
}
List ReadPoly()
{
    //读入要存储的次数
    int total, read;//柜子总数,询问次数
    int n,m,k,q;
    scanf("%d %d",&total,&read);
    List front,rear,temp;
    front = (List)malloc(sizeof(struct Node));
    front-> Next = NULL;
    rear = front;
    for(int i=0;i<read;i++)
    {
        scanf("%d %d %d %d",&n,&m,&k,&q);
        if(m<total)
        {
            Attach(n,m,k,q,&rear);//将当前项插入尾部
        }
    }
    temp = front;
    front = front->Next;
    free(temp);
    return front;
}
void Attach(int n,int m,int k,int q,In *Prear)
{
    List p;
    p = (List)malloc(sizeof(struct Node));
    p->n = n;
    p->m = m;
    p->k = k;
    p->q = q;
    (*Prear)->Next= p;
    (*Prear) = p;//修改rear的值存放数据                          
}
void PrintSearch(List Prear)
{
    int result;
    List p;
    p = Prear;
    while(p)
    {
        if(p->n == 2)//表示要搜取这个箱子
        {
            result = p->q;
            printf("%d\n",result);
        }
    }
}

by AlgoEmperor @ 2022-03-10 14:31:52

这啥


by zbj15010210485 @ 2022-03-10 14:37:00

@NyaRu_Official 我用C语言实现的,但是不知道为啥全部RE


by gg158 @ 2023-08-06 22:16:46

@zbj15010210485 超时了


|