Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4439 Accepted Submission(s): 2265
4 4 FIFO IN 1 IN 2 OUT OUT 4 FILO IN 1 IN 2 OUT OUT 5 FIFO IN 1 IN 2 OUT OUT OUT 5 FILO IN 1 IN 2 OUT IN 3 OUT
1 2 2 1 1 2 None 2 3
#include<stdio.h> #include<string.h> int c[10000],b[10000]; int main() { int n; scanf("%d",&n); while(n--) { int m,t,j,j1,j2; char a[5],s[5]; scanf("%d%s",&m,a); if(!strcmp(a,"FILO")) { j=j1=j2=0; while(m--) { scanf("%s",s); if(!strcmp(s,"IN")) { scanf("%d",&t); c[j++]=t; j2++; } else { if(j==0) printf("None\n"); else { printf("%d\n",c[j-1]); j--; } } } } else if(!strcmp(a,"FIFO")) { j=j1=j2=0; while(m--) { scanf("%s",s); if(!strcmp(s,"IN")) { scanf("%d",&t); b[j++]=t; } else { if(j1>=j) printf("None\n"); else { printf("%d\n",b[j1++]); } } } } } return 0; }
#include<stdio.h> #include<queue> #include<string.h> #include<stack> #include<iostream> using namespace std; int main() { int n; scanf("%d",&n); while(n--) { char a[10]; int m; scanf("%d%s",&m,a); if(!strcmp(a,"FIFO")) { queue<int> q; while(m--) { char s[10]; scanf("%s",s); if(!strcmp(s,"IN")) { int b; scanf("%d\n",&b); q.push(b); } else { if(q.empty()) printf("None\n"); else { printf("%d\n",q.front()); q.pop(); } } } } else { stack<int>w; while(m--) { char s[10]; scanf("%s",s); if(!strcmp(s,"IN")) { int b; scanf("%d",&b); w.push(b); } else { if(w.empty()) printf("None\n"); else { printf("%d\n",w.top()); w.pop(); } } } } } return 0; }