#include <stdio.h>
#include <string.h>
int main()
{
int m , j , k , n , a[20002] = {0} , front , tail ;
char str[10] ;
scanf("%d", &m);
for(tail = 1 ; tail <= m ; tail++)
scanf("%d", &a[tail]);
front = 1 ;
scanf("%d", &n);
for(j = 0 ; j < n ; j++)
{
scanf("%s", str);
if(!strcmp(str,"JOIN"))
{
scanf("%d", &a[tail++]);
}
else if(!strcmp(str,"LEAVE"))
{
scanf("%d", &m);
for(k = m-1+front ; k < tail ; k++)
a[k] = a[k+1] ;
a[tail-1] = 0 ;
tail--;
}
else if(!strcmp(str,"ASK"))
{
scanf("%d", &m);
printf("%d\n", a[m-1+front]);
}
else if(!strcmp(str,"FINISH"))
{
scanf("%d", &m);
front = m+front ;
}
else
{
printf("%d\n", tail-front);
}
}
return 0;
}
java实现学生就餐问题完整代码
最新推荐文章于 2024-07-27 13:31:57 发布