当前位置: 代码迷 >> 综合 >> HOJ 1702 ACboy needs your help again!(stack 和 queue,巨水)
  详细解决方案

HOJ 1702 ACboy needs your help again!(stack 和 queue,巨水)

热度:18   发布时间:2023-12-13 19:09:42.0

stack 和 queue,巨水
本题要点:
1、直接用stl的 stack 和 queue来模拟即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
int T, n, flag;
char cmd[10];void solve(bool flag)
{
    queue<int> q;stack<int> st;int x;for(int i = 0; i < n; ++i){
    scanf("%s", cmd);if(cmd[0] == 'I'){
    scanf("%d", &x);if(flag)q.push(x);elsest.push(x);}else{
    if(flag){
    if(q.empty()){
    printf("None\n");}else{
    x = q.front();	q.pop();printf("%d\n", x);}}else{
    if(st.empty()){
    printf("None\n");}else{
    x = st.top(); st.pop();printf("%d\n", x);}}}}
}int main()
{
    scanf("%d", &T);bool flag;while(T--){
    scanf("%d%s", &n, cmd);if(strcmp(cmd, "FIFO") == 0)	//队列{
    flag = true;	}else{
    	//栈flag = false;}solve(flag);}return 0;
}/* 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 */
  相关解决方案