HDU1702

简介: ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1789    Accepted Submission(s): 963 Problem Description

ACboy needs your help again!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1789    Accepted Submission(s): 963


Problem Description
ACboy was kidnapped!! 
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!
 

Input
The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
 

Output
For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.
 

Sample Input
 
 
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
 

Sample Output
 
 
1 2 2 1 1 2 None 2 3
 

Source
#include <queue>
#include <stack>
#include <string>
#include<stdio.h>
#include<iostream>
using namespace std;

int main()

{    int t,n,temp,i;

    scanf("%d",&t);

    while(t--)

    {    string str,str1;

        queue<int>Q;
        stack<int>S;
        scanf("%d",&n);
        cin>>str;
        for(i=0; i<n; i++)
        {    if(str=="FIFO")
            {    cin>>str1;
                if(str1=="IN")
                {    scanf("%d",&temp);
                    Q.push(temp);
                }
                if(str1=="OUT")
                {    if(Q.empty())
                        printf("None\n");
                    else      {
                        printf("%d\n",Q.front());
                        Q.pop();
                    }
                }
            }            else
            {    cin>>str1;
                if(str1=="IN")
                {    scanf("%d",&temp);
                    S.push(temp);
                }
                if(str1=="OUT")
                {    if(S.empty())
                        printf("None\n");
                    else {
                        printf("%d\n",S.top());
                        S.pop();
                    }
                }
            }
        }
    }
    return 0;
}


目录
相关文章
|
中间件 Go 数据库
Go开发者必读:Gin框架的实战技巧与最佳实践
在当今快速发展的互联网时代,Web开发的需求日益增长。Go语言以其简洁、高效、并发性强的特点,成为了开发者们的首选。而在Go语言的众多Web框架中,Gin无疑是其中的佼佼者。本文将深入探讨Gin框架的特性、优势以及如何利用Gin构建高性能的Web应用。
|
SQL 消息中间件 分布式计算
12中方法,彻底搞定数据倾斜!
12中方法,彻底搞定数据倾斜!
|
存储 JavaScript 测试技术
rpmdb损坏的修复方法
yum强制终止后,提示rpmdb损坏 error: cannot open providename index using db3 - bad file descriptor
9965 0
|
10月前
|
存储 安全 前端开发
编写加密解密工具函数时,如何处理密钥的安全性?
编写加密解密工具函数时,如何处理密钥的安全性?
1036 153
|
SQL 开发框架 Ubuntu
阿里云轻量应用服务器系统镜像和应用镜像区别及选择
阿里云轻量应用服务器可选应用镜像和系统镜像,应用镜像和系统镜像有什么如何?阿里云轻量应用服务器操作系统如何选择镜像?笔者分享阿里云轻量应用服务器应用镜像和系统镜像的区别及选择方法:
阿里云轻量应用服务器系统镜像和应用镜像区别及选择
|
6月前
|
存储 人工智能 Serverless
Serverless AI Agent 实战:用阿里云 AgentRun + Google ADK 搭建多智能体协同工作流
本文详解如何在阿里云AgentRun上快速搭建基于Google A2A协议的多Agent竞品分析系统:搜索、分析、报告三个专业Agent通过Serverless架构协同工作,内置百炼大模型与NAS共享存储,开箱即用、按量计费,显著降低多Agent落地门槛。
|
存储 数据库 云计算
服务器有哪些功能?网站托管/CDN加速/云计算部署必知方案
本文系统解析服务器在网站托管、应用服务、数据管理、协同办公及云计算等方面的核心功能与技术演进,涵盖CDN加速、虚拟化、容器化、网络安全等关键方案,揭示其作为数字中枢在推动数字化转型中的重要作用。转载链接:https://www.ffy.com/latest-news/1917106730248966144
739 153
服务器有哪些功能?网站托管/CDN加速/云计算部署必知方案
|
7月前
|
存储 人工智能 弹性计算
2026年阿里云服务器便宜购买指南:最新优惠政策、配置选择与省钱技巧
2026年阿里云推出多项云服务器优惠活动,轻量应用服务器2核2G配置仅需38元/年,经济型e实例2核2G 99元/年,通用算力型u1实例2核4G 199元/年。此外,u2i实例享3折起,第九代实例低至6.4折。用户可通过新用户特惠、优惠券及组合购策略,如先购高配产品、使用购物车合并支付、参与组合购活动等,进一步降低成本。通过这些政策和技巧,用户能以更低价格选购适合的云服务器。
|
8月前
|
人工智能 数据可视化 API
上阿里云百炼免费体验HappyHorse:新一代AI视频生成模型,免费体验3步成功
阿里云HappyHorse是新一代AI视频生成模型,免费体验:https://t.aliyun.com/U/0UlOFR 支持文生视频、图生视频及视频编辑,具备电影级光影质感、多模态创作能力与超高性价比。新用户可免费体验10秒,720P视频低至0.9元/秒。登录阿里云百炼平台,三步即可开启AI视频创作之旅。
|
12月前
|
人工智能 运维 监控
适合中小企业的BI产品推荐,涵盖国内外10款热门产品
文章构建“中小企业BI选型五维模型”(易用性、成本、数据源适配、智能化、服务生态),并深度解析国内外10款主流BI产品(瓴羊Quick BI、Microsoft Power BI、Tableau、Zoho Analytics、Wyn BI、DataFocus、永洪Z-Suite、Qlik Sense 、Looker、Metabase)。其中,阿里云旗下瓴羊Quick BI凭借AI助手“智能小Q”、连续6年入选Gartner魔力象限、SaaS轻量化部署及对淘宝、钉钉等本土生态的深度集成,展现出突出的中小企业适配能力。