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: 1124kB
Author: 2018212212247
In contest: 1284

#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,d,f,j,p,i;
	int a[10];
	char s[20];
	scanf("%d%d",&n,&m);
	f=0;
	j=0;
	getchar();
	while(m--)
	{
		gets(s);
		if(s[4]=='L')
		{
			i=strlen(s)-1;
			d=s[i]-'0';
			i--;
			while(s[i]!=' ')
			{
				d+=(s[i]-'0')*10;
				i--;
			}
			}
		else
		{
			i=strlen(s)-1;
			d=s[i]-'0';
			i--;
			while(s[i]!=' ')
			{
				d+=(s[i]-'0')*10;
				i--;
			}
		}
		if(strncmp(s,"pushLeft",8)==0)
		{
			if(f<n)
			{
				for(p=j;p>0;--p)
					a[p]=a[p-1];
				a[0]=d;
				j++;
				printf("Pushed in left: %d\n",d);
				f++;
			}
			else
				printf("The queue is full\n");
		}
		else if(strncmp(s,"pushRight",9)==0)
		{
			if(f<n)
			{
				a[j]=d;
				j++;
				printf("Pushed in right: %d\n",d);
				f++;
			}
			else
				printf("The queue is full\n");
		}
		else if(strcmp(s,"popLeft")==0)
		{
			if(f>0)
			{
				printf("Popped from left: %d\n",a[0]);
				for(p=0;p<j-1;++p)
					a[p]=a[p+1];
				j--;
				f--;
			}
			else
				printf("The queue is empty\n");
		}
		else if(strcmp(s,"popRight")==0)
		{
			if(f>0)
			{
				printf("Popped from right: %d\n",a[j-1]);
				j--;
				f--;
			}
			else
				printf("The queue is empty\n");
		}
	}
	return 0;
}