- /*这题的错误是和同学熬夜找出来的呃= =。。。*/
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int front,rear,i,f,j,n,t,q[10000];
- char s[20];
- scanf("%d",&n);
- rear =0,front=0;
- for(i=0;i<n;i++)
- {
- rear=i;
- scanf("%d",&q[rear]);
- }
- scanf("%d",&n);
- for(i = 0; i < n; i++)
- {
- scanf("%s",s);
- if(strcmp(s,"ASK") == 0)
- {
- scanf("%d",&f);
- printf("%d\n",q[front+f-1]);
- }
- else if (strcmp(s,"JOIN") == 0)
- {
- scanf("%d",&f);
- rear++;
- q[rear] = f;
- }
- else if(strcmp(s,"FINISH") == 0)
- {
- scanf("%d",&f);
- front=front+f;
- }
- else if(strcmp(s,"LEAVE") == 0)
- {
- scanf("%d",&f);
- for(j = front + f -1;j >front;j--)
- {
- q[j]=q[j-1];
- }
- front++;
- }
- else if(strcmp(s,"LENGTH") == 0)
- {
- printf("%d\n",rear-front+1);
- }
- }
- }