Start: Jul, 10, 2019 08:30:00
2019年度暑期短学期达标测试补考
End: Jul, 10, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: I
Result: Accepted
Time: 3ms
Memory: 1120kB
Author: 2018212212113
In contest: 1284

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

int main() {
	int N, M;
	int cod;
	int queue[60];
	int lft, rit;
	char cmd[20];
	char cmd1[]="pushLeft", cmd2[]="pushRight", cmd3[]="popLeft", cmd4[]="popRight";

	scanf("%d %d", &N, &M);
	lft = 30;
	rit = 31;
	while (M--) {
		scanf("%s", cmd);
		if (!strcmp(cmd, cmd1)) {
			scanf("%d", &cod);
			if ((rit-lft) >= N+1) {
				printf("The queue is full\n");
			} else {
				queue[lft] = cod;
				lft -= 1;
				printf("Pushed in left: %d\n", queue[lft+1]);
			}
		} else if (!strcmp(cmd, cmd2)) {
			scanf("%d", &cod);
			if ((rit-lft) >= N+1) {
				printf("The queue is full\n");
			} else {
				queue[rit] = cod;
				rit += 1;
				printf("Pushed in right: %d\n", queue[rit-1]);
			}
		} else if (!strcmp(cmd, cmd3)) {
			if ((rit-lft) <= 1) {
				printf("The queue is empty\n");
			} else {
				lft += 1;
				printf("Popped from left: %d\n", queue[lft]);
			}
		} else if (!strcmp(cmd, cmd4)) {
			if ((rit-lft) <= 1) {
				printf("The queue is empty\n");
			} else {
				rit -= 1;
				printf("Popped from right: %d\n", queue[rit]);
			}
		}
	}

	return 0;
}