救助!4点全错!大佬帮帮孩子
查看原帖
救助!4点全错!大佬帮帮孩子
440825
no_echo楼主2020/11/23 21:47

能在编译器上实现,但是提交出错

#include <stdio.h>
#include <string.h>

typedef struct LNode
{
    long data;
    struct LNode* next;
}* list;

list read( long num )
{
    list h = (list)malloc(sizeof(struct LNode));
    h -> next = NULL;
    list s = NULL, p =NULL;
    p = h;
    for(long i = 0 ; i< num ; i++)
    {
        s = (list)malloc(sizeof(struct LNode));
        scanf("%d\n",&(s -> data));
        p -> next = s;
        p = s;
    }
    s -> next = NULL;
    return h;
}

void ask(list h, long times)
{
    int n;
    list l = h -> next;
    int j = 1;
    for(int i = 0; i < times ; i++)
    {
        scanf("%d",&n);
        while(l!=NULL && j < n )
        {
            l = l -> next;
            j++;
        }
        printf("%d",l -> data);
        if( i != times - 1)
        {
            printf("\n");
        }
    }
}

int main(void)
{
    long num;
    int times;
    scanf("%d\n%d",&num,&times);
    list L = read(num);
    ask(L,times);
    return 0;
}
2020/11/23 21:47
加载中...