33分求助
查看原帖
33分求助
1286330
czy571119025楼主2024/9/17 11:04
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <assert.h>
#include <time.h>

typedef struct {
	unsigned long long* base;
	unsigned long long* top;
	unsigned long long stacksize;
	unsigned long long size;
}STACK;

STACK* s;

void f(char c[], unsigned long long x) {
	if (c[0] == 'p' && c[1] == 'u' && c[2] == 's' && c[3] == 'h') {
		*(s->top) = x;
		s->top++;
		s->size++;
		return;
	}
	if (c[0] == 'p' && c[1] == 'o' && c[2] == 'p') {
		if (s->top == s->base) {
			printf("Empty\n");
			return;
		}
		s->top--;
		s->size--;
		return;
	}
	if (c[0] == 'q' && c[1] == 'u' && c[2] == 'e' && c[3] == 'r' && c[4] == 'y') {
		if (s->top == s->base) {
			printf("Anguei!\n");
			return;
		}
		s->top--;
		unsigned long long ans = *(s->top);
		printf("%lld\n", ans);
		s->top++;
		return;
	}
	if (c[0] == 's' && c[1] == 'i' && c[2] == 'z' && c[3] == 'e') {
		printf("%d\n", s->size);
		return;
	}
}

int main()
{
	
	int T;
	scanf("%d", &T);
	while (T--) {
		s = (STACK*)malloc(sizeof(STACK));
		s->base = (unsigned long long*)malloc(1000010 * sizeof(unsigned long long));
		s->top = s->base;
		s->stacksize = 1000010;
		s->size = 0;

		int n;
		scanf("%d", &n);
		while (n--) {
			char c[10];
			unsigned long long x = 0;
			scanf("%s", c);
			if (c[0] == 'p' && c[1] == 'u' && c[2] == 's' && c[3] == 'h') {
				scanf("%lld", &x);
			}
			f(c, x);
		}

	}
	return 0;

}
2024/9/17 11:04
加载中...