zoukankan      html  css  js  c++  java
  • 【杭电】[1702]ACboy needs your help again!

    这里写图片描述
    这里写图片描述
    这里写图片描述

    题目给出两种形式
    FIFO先进先出
    FILO先进后出
    分别对应队列和栈
    (队列先进先出,栈先进后出)

    所以直接模拟就好了
    特别注意的就是对于两种结构
    各个命令的记忆需要准确

    #include<stdio.h>
    #include<string.h>
    #include<stack>
    #include<queue>
    using namespace std;
    stack<int>a;
    queue<int>q;
    int main() {
        int T;
        scanf("%d",&T);
        while(T--) {
            int n;
            char s[10];
            scanf("%d %s",&n,s);
            if(strcmp(s,"FIFO")==0) {
                while(n--) {
                    char st[10];
                    scanf("%s",st);
                    if(strcmp(st,"IN")==0) {
                        int t;
                        scanf("%d",&t);
                        q.push(t);
                    } else {
                        if(q.empty())
                            printf("None
    ");
                        else {
                            printf("%d
    ",q.front());
                            q.pop();
                        }
                    }
                }
            } else {
                while(n--) {
                    char st[10];
                    scanf("%s",st);
                    if(strcmp(st,"IN")==0) {
                        int t;
                        scanf("%d",&t);
                        a.push(t);
                    } else {
                        if(a.empty())
                            printf("None
    ");
                        else {
                            printf("%d
    ",a.top());
                            a.pop();
                        }
                    }
                }
            }
            while(!a.empty())
                a.pop();
            while(!q.empty())
                q.pop();
        }
        return 0;
    }
    

    题目地址:【杭电】[1702]ACboy needs your help again!

  • 相关阅读:
    window下启动tomcat输出日志乱码
    Mybatis
    JAVA-Stream
    记录-linux安装supervisor来监控elasticsearch
    草稿
    定时任务
    阿里云linux6.9 64位安装mysql5.7.23记录
    归并排序
    快速排序
    HTML DOM
  • 原文地址:https://www.cnblogs.com/BoilTask/p/12569739.html
Copyright © 2011-2022 走看看