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: 4ms
Memory: 1120kB
Author: 2018212212112
In contest: 1284

#include<stdio.h>
#include<string.h>
int main(){
	int N,M;
	int b[20];
	char a[20];
	char name[20];
	int num,count=0,j,i;
	scanf("%d%d",&N,&M);
	getchar();
	while(M--){
		num = 0; 
		scanf("%[^\n]",name);
		getchar();
		for(i=0;i<7;i++){
			a[i] = name[i];
		}
		if(strcmp(a,"pushLef")==0){
			if(count==N){
				printf("The queue is full\n");
			}else{
				for(j=9;name[j]!='\0';j++){
					num = num * 10 +  name[j] - '0'; 
				}
				for(i=count-1;i>=0;i--){
					b[i+1] = b[i];
				}
				b[0] = num;
				count++;
				printf("Pushed in left: %d\n",num);
			}
		}else if(strcmp(a,"pushRig")==0){
			if(count==N){
				printf("The queue is full\n");
			}else{
				for(j=10;name[j]!='\0';j++){
					num = num * 10 +  name[j] - '0'; 
				}
				b[count] = num;
				count++;
				printf("Pushed in right: %d\n",num);
			}
		}else if(strcmp(a,"popLeft")==0){
			if(count==0){
				printf("The queue is empty\n");
			}else{
				printf("Popped from left: %d\n",b[0]);
				for(i=0;i<count-1;i++){
					b[i] = b[i+1];
				}
				count--;
				
			}
		}else if(strcmp(a,"popRigh")==0){
			if(count==0){
				printf("The queue is empty\n");
			}else{
				printf("Popped from right: %d\n",b[count-1]);
				count--;
			}
		}
	}
}