c语言

#include <stdio.h>

struct stack {

    int data[100000];

    int t;

};

void push(struct stack *sint x);

void pop(struct stack *s);

void top(struct stack *s);

int main() {

    struct stack s;

    struct stack* p;

    p = &s;

    s.t = 0;

    int n, x;

    char ch;

    scanf("%d", &n);

    getchar();

    while (n--) {

        scanf("%c",&ch);

        if (ch == 'p') {

            scanf("%c",&ch);

            if (ch == 'u') {

                getchar();

                getchar();

                getchar();

                scanf("%d",&x);

                push(p, x);

            }

            else {

                getchar();

                pop(p);

            }

        }

        else{

            getchar();

            getchar();

            top(p);

        }

        getchar();

    }

    return 0;

}

void push(struct stack *sint x) {

    s->data[s->t] = x;

    s->t++;

}

void pop(struct stack *s) {

    if (s->t > 0) {

        s->t--;

        printf("%d\n"s->data[s->t]);

    }

    else printf("error\n");

}

void top(struct stack *s) {

    if (s->t > 0) {

        printf("%d\n"s->data[s->t - 1]);

    }

    else printf("error\n");

}