ACboy needs your help again!(c++std)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702
题目大意:输入FIFO或FILO说明是使用队列还是栈,输入IN或OUT说明是入队(栈)还是出队(栈)
分析:使用<stack>和<queue>即可轻松实现
AC代码:
#include <stack> #include <stdio.h> #include <vector> #include <string.h> #include <queue> using namespace std; int main() { int N,c,i,j; char kind[4],command[3]; scanf("%d",&N); while(N--) { j = 0; stack<int,vector<int> > a; scanf("%d %s",&c,kind); if (!strcmp(kind,"FILO")) { for (i=0;i<c;i++) { scanf("%s",command); if (!strcmp(command,"IN")) { scanf("%d",&j); a.push(j); } else if(a.empty()) printf("None\n"); else { printf("%d\n",a.top()); a.pop(); } } } else { queue <int> a; for (i=0;i<c;i++) { scanf("%s",command); if (!strcmp(command,"IN")) { scanf("%d",&j); a.push(j); } else if(a.empty()) printf("None\n"); else { printf("%d\n",a.front()); a.pop(); } } } } return 0; }
Hello World qwq!

浙公网安备 33010602011771号