66 lines
1.5 KiB
C
66 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int opcodeToNum(char* opcode);
|
|
|
|
int main() {
|
|
int N;
|
|
scanf("%d\n",&N);
|
|
int queue[10000];
|
|
int front = 0, rear = 0, size = 0;
|
|
|
|
while(N--){
|
|
char opcode[6];
|
|
int operend;
|
|
scanf("%s",opcode);
|
|
|
|
switch(opcodeToNum(opcode))
|
|
{
|
|
case 0:
|
|
{
|
|
scanf("%d\n",&operend);
|
|
queue[rear++] = operend;
|
|
size++;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
printf("%d\n", size ? queue[front++] : -1);
|
|
size = size ? size - 1 : 0;
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
printf("%d\n",size);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
printf("%d\n", size ? 0 : 1);
|
|
break;
|
|
}
|
|
case 4:
|
|
{
|
|
printf("%d\n", size ? queue[front] : -1);
|
|
break;
|
|
}
|
|
case 5:
|
|
{
|
|
printf("%d\n", size ? queue[rear-1] : -1);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int opcodeToNum(char* opcode){
|
|
if(!strcmp(opcode, "push")) return 0;
|
|
else if(!strcmp(opcode, "pop")) return 1;
|
|
else if(!strcmp(opcode, "size")) return 2;
|
|
else if(!strcmp(opcode, "empty")) return 3;
|
|
else if(!strcmp(opcode, "front")) return 4;
|
|
else if(!strcmp(opcode, "back")) return 5;
|
|
return -1;
|
|
}
|