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: 2018212212304
In contest: 1284

#include<stdio.h>
#include<string.h>
int main() {
	int n,m,h,j,j1,j2,he[12],i,g1,g2;
	char s[101];
	scanf("%d %d",&n,&m);
	j=0;
	j1=0;
	j2=0;
	for(i=0; i<=11; ++i) {
		he[i]=-1;
	}
	getchar();
	while(m--) {
		scanf("%s",s);
		if(strcmp(s,"pushLeft")==0) {
			scanf("%d",&h);
			if(j==n) {
				printf("The queue is full\n");
			} else {
				printf("Pushed in left: %d\n",h);
				he[5-j1]=h;
				j1++;
				j++;
			}
		}
		if(strcmp(s,"pushRight")==0) {
			scanf("%d",&h);
			if(j==n) {
				printf("The queue is full\n");
			} else {
				printf("Pushed in right: %d\n",h);
				he[6+j2]=h;
				j2++;
				j++;
			}
		}
		if(strcmp(s,"popLeft")==0) {
			if(j==0) {
				printf("The queue is empty\n");
			} else {
				for(i=0; i<=11; ++i) {
					if(he[i]!=-1) {
						g1=i;
						break;
					}
				}
				printf("Popped from left: %d\n",he[g1]);
				he[g1]=-1;
				j--;
				j1--;
			}
		}
		if(strcmp(s,"popRight")==0) {
			if(j==0) {
				printf("The queue is empty\n");
			} else {
				for(i=11; i>=0; --i) {
					if(he[i]!=-1) {
						g2=i;
						break;
					}
				}
				printf("Popped from right: %d\n",he[g2]);
				he[g2]=-1;
				j--;
				j2--;
			}
		}
	}
	return 0;
}