大佬救救孩子
查看原帖
大佬救救孩子
861113
wanan2203ouchengli楼主2023/8/16 21:06

我在自己编译器过了,但是在洛谷上过不了

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#define V 10005

typedef struct N {
    int b;
    struct N* next;
}N,* L;
typedef struct  {
    L front;
    L rear;
}M;

void CSH(M& l) {
    l.front = l.rear = new N;
    l.front->next = l.rear->next = NULL;
}

void RD(M& l, int x) {
    L p;
    p = new N;
    p->b = x;
    p->next = NULL;
    l.rear->next = p;
    l.rear = p;
}

int CD(M& l,int t) {
    if (l.rear == l.front) {
        return 0;
    }
    L p;
    p = l.front->next;
    if (t == 3) {
        printf("%d\n", p->b);
    }
    l.front->next=p->next;
    if (p == l.rear) {
        l.rear = l.front;
    }
    return 1;
}

int main() {
    int n,s=0;
    int a[V];
    M l;
    CSH(l);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] == 1) {
            n++;
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            RD(l,a[i+1]);
            i++;
            s++;
        }
        else {
            if (a[i] == 2) {
                int y = CD(l, 2);
                if (y == 0) {
                    printf("ERR_CANNOT_POP\n");
                }
                s--;
            }
            else {
                if (a[i] == 3) {
                    if (l.front->next == NULL) {
                        printf("ERR_CANNOT_QUERY\n");
                    }
                    else {
                        printf("%d\n", l.front->next->b);
                    }
                }
                else {
                    if (a[i] == 4) {
                        printf("%d\n", s);
                    }
                }
            }
        }
    }
    return 0;
}
2023/8/16 21:06
加载中...