题解 | #【模板】队列#
【模板】队列
https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549
#include <stdio.h> #include<string.h> #include <stdlib.h> int arr[100000],sum=0,first=0; void push(int x) { arr[sum++]=x; } void front() { if(sum==first) printf("error\n"); else printf("%d\n",arr[first]); } void pop() { if(sum==first) printf("error\n"); else printf("%d\n",arr[first++]); } int main() { int n; scanf("%d",&n); getchar(); while(n--) { int x=0; char str[10]; int number=0; scanf("%s", str); if (strcmp(str, "push") == 0) scanf("%d", &x); if (strcmp(str, "front") == 0) front(); else if (strcmp(str, "pop") == 0) pop(); else if (strcmp(str, "push") == 0) push(x); getchar(); } return 0; }