ACboy needs your help again!(栈和队列简单应用)

hdu1702(ACboy needs your help again!) 在杭电又遇坑了 点击打开链接 结题感悟: 其实吧,这题并不是很难,就是一个栈和队列的公共题,也就是按指定的方式(栈或队列)存取数据,但是为什么我自己写的栈和队列就是不能再杭电ac,而用java包中的栈和队列就秒过了,问题尚未找出原因,值得思考啊。不过可以趁此学学这两个类(尽量还是自己动手写的好啊) 栈:java.util 类 Stack Stack 类表示后进先出(LIFO)的对象堆栈。它通过五个操作 阅读详情

ACboy needs your help again!

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


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
 


#include<stdio.h>  
#include<string.h>  
#include<algorithm>  
#include<stack>  //栈 
#include<queue>  //队列 
using namespace std;  
queue <int> q;  //定义队列q 
stack <int> s;  //定义栈s 
int i,n,m,j,k,l;  
char c[100],ch[100];  
int main()  
{  
    scanf("%d",&n);  
    while(n--)  
    {  
        while(!s.empty())  //清空栈s 
        s.pop();   
        while(!q.empty())  //清空队列q 
        q.pop();  
        scanf("%d %s",&m,c);  
        if(strcmp(c,"FIFO")==0){
        for(i=0;i<m;i++)  
        {  
            scanf("%s",ch);  
            if(strcmp(ch,"IN")==0)  
            {  
                scanf("%d",&k);  
                q.push(k);  //将k读入队列q 
            }  
            else  
             {  
                if(!q.empty())  //判断队列q是否为空 
                {  
                printf("%d\n",q.front());  //将队列q按先进先出的顺序输出    front指队列最前边(最先读入的数字)的数 
                q.pop();  // 将队列最前边的数字输出后,那个数字仍然在队列里边,,,用q.pop();将输出的数抛出队列 
                }  
                else  
                printf("None\n");  
             }  
        }
	}
        else  
        {  
            for(i=0;i<m;i++)  
            {  
                scanf("%s",ch);  
                if(strcmp(ch,"IN")==0)  
                {  
                    scanf("%d",&k);  
                    s.push(k);   //将k读入栈s 
                }  
                else  
                {  
                    if(!s.empty())  
                    {  
                        printf("%d\n",s.top());  //将栈按先进后出的顺序输出    top指栈的最上边的数(最后读入的数) 
                        s.pop();  //将输出的数抛出栈 
                    }  
                    else  
                    printf("None\n");  
                }  
            }  
        }  
    }  
    return 0;  
}//   杭电1702ACboy needs your help again!		栈和队列简单应用的模板


tmux + Claude Code 远程开发指南:从 WSL 配置到断线无忧 远程开发中,SSH 连接中断常导致后台任务丢失,这是困扰开发者的经典难题。tmux 作为终端复用器,通过将进程挂在常驻会话中,使其脱离 SSH 连接独立运行,从根本上解决了断线导致的任务终止问题。Claude Code 等 AI 编程代理需要长时间运行并保持交互上下文,恰好依赖这种会话持久化能力。结合 Windows Subsystem for Linux 提供类 Unix 环境,开发者可在 Windows 上实现稳定的远程开发工作流。本文将完整介绍从 WSL 环境配置、tmux 会话管理,到与 Claud 阅读详情

相关推荐

MacX DVD Ripper Pro for Mac(DVD解码器) 6.2.120190416免激活版

只需要5分钟即可转档一张DVD光碟!并允许我们在编码之前预览、编辑、裁剪、修剪或扩展视频。第一款也是唯一一款能够支持DVD到MP4,H.264,MOV,FLV,MPEG4等所有格式DVD(新DVD,99-标题DVD,损坏和无法播放的DVD)和翻录DVD / ISO映像的工具,AVI,QT,MP3等。借助350多种预设配置文件MacX DVD Ripper Pro for Mac(DVD解码器) 6...

llhf688的博客 896

ACboy needs your help again!(栈和队列)HDU - 1702

题目:ACboy needs your help again! 中文大意 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

R_711的博客 446

Python + DeepSeek 完美结合:本地部署提效指南

随着生成式 AI 和深度学习技术的快速发展,如何将智能搜索工具与本地部署结合以提升效率成为了许多企业和开发者关注的重点。DeepSeek 是一款开源的智能搜索框架,结合 Python 的灵活性,能够实现高效、可靠的本地部署方案。本文将介绍如何通过 Python 和 DeepSeek 的完美结合,实现本地化部署并提升工作效率。通过将 Python 与 DeepSeek 结合,可以快速实现语义搜索的本地化部署,确保数据安全的同时提升工作效率。文件可直接作为 DeepSeek 的输入数据。

weixin_44872675的博客 1万+

HDOJ-1702 栈和队列问题[或模拟]

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1697    Accepted Submission(s): 906 Problem Description ACboy wa...

weixin_34226182的博客 552

macOS向日葵闪退终极修复:权限设置与后台运行全解析

本文详细解析了macOS上向日葵远程控制软件闪退问题的根源与解决方案,重点介绍了权限设置与后台运行的优化方法。通过配置屏幕录制、辅助功能等关键权限,以及优化后台进程管理,有效解决闪退问题,提升远程控制软件的稳定性与使用体验。

fern8的博客 1784

手把手配置:用Synopsys VDK为英飞凌TC4x系列MCU做虚拟原型开发

本文详细介绍了如何使用Synopsys VDK为英飞凌TC4x系列MCU进行虚拟原型开发,涵盖开发环境搭建、关键外设虚拟化配置、AUTOSAR栈集成及虚拟调试与性能调优全流程。通过虚拟原型技术,开发者可提前6-12个月启动软件开发,显著提升汽车电子项目的开发效率。

weixin_30606461的博客 295

【STL基础01】HDU-1702-ACboy needs your help again!

题目来源:https://cn.vjudge.net/problem/HDU-1702 题目大意: 编程实现栈(stack)和队列(queue)。 解题思路: 栈(先进后出),队列(先进先出)。 AC代码: #include #include #include #define N 100 #define M 10 void FIFO(c

雄英通信站 344

万达电影 com.wandafilm.app headers check

万达电影 安卓逆向 抓包 逆向 check

weixin_43786514的博客 1442

HDU 1702 ACboy needs your help again!

#include #include #include #include using namespace std; int main() { int t; cin>>t; while(t--) { int n;string cmd; cin>>n>>cmd; queue q; stack ss;

qq_33901573的博客 281

华为OD机试双机位C卷-停车场收入统计 (Py/Java/C/C++/Js/Go)

华为OD机试双机位C卷 停车场收入统计,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试 - 停车场收入统计。

qq_45776114的博客 2190

建行报专版报道建设银行金融科技发展历程

经过十多年的建设,总行前中后台部门都有了自己的业务系统,但系统“部门”特征显著,渠道、客户、产品的横向整合不足,产品系统层次化、结构化、参数化程度不高,渠道支持产品快速部署以及跨渠道服务能力不足,管理分析类系统建设相对滞后,系统较弱的可扩展能力在应对高速增长的交易量时已疲态尽显,同时安全稳定运行的压力和风险日益积聚。站在新的历史起点上,科技条线将聚焦主责主业,完善信息科技管理体系,紧紧围绕安全生产中心任务,持续推动技术能力复用共享和自主可控,为全行做好金融五篇大文章,推动业务高质量发展提供技术支撑。

银行信息系统应用架构详解 396

ACboy needs your help again!

栈,队列

weixin_73793099的博客 147

mojoPortal 路径穿越漏洞复现(CVE-2025-28367)(附脚本)

 在 mojoPortal CMS 版本 <=2.9.0.1 中发现了一个导致 ViewState 反序列化的目录遍历漏洞。通过利用此问题,未经身份验证的攻击者可以泄露 Web 根目录中的敏感文件,包括应用程序的文件。此配置文件包含用于验证和解密 ViewState 数据的文件。知道此密钥后,网络攻击者可以构建恶意 ViewState 有效负载,从而导致在底层服务器上执行远程代码。(CVE-2025-28367)

iSee857的博客 503

栈和队列的应用【ACboy needs your help again、C++】

题目描述 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,

qq_22841387的博客 1273

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

HDU - ACboy needs your help again!(链式队列&栈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description ACboy was kidnapped!! he miss his mother very...

ityanger的技术栈 2759

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

杭电-1702 ACboy needs your help again!(栈&队列)

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5670    Accepted Submission(s): 2963 Problem Descript

lu_1110的博客 1139

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ACboy needs your help again! (队列问题)

ACboy needs your help again! 目录 ACboy needs your help again! 题意描述:多实例,根据输入单词是"FIFO"或"FILO",即是queue还是stack以及输入in求每个命令"OUT",应该输出的整数,没有任何整数输出“None"。 解题思路:分两个大方向fifo为队列先进先出、filo栈先进后出,然后当in时再输入数字加入队列、栈顶,out时若建立的队列和栈不空时,根据队列和栈的输出格式进行输出;当栈或队列里面元素为空时,输出Non...

m0_58245389的博客 625

栈与队列的简单理解(ACboy needs your help again!)

一、队列: 队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表。进行插入操作的端称为队尾,进行删除操作的端称为队头。队列中没有元素时,称为空队列。 二、栈: 栈(stack)又名堆栈,它是一种运算受限的线性表。其限制是仅允许在表的一端进行插入和删除运算。这一端被称为栈顶,相对地,把另一端称为...

Bearing in mind forever! 734

HDU1702 ACboy needs your help again!【模拟】

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12266 Accepted Submission(s): 6064 Problem Description ACboy wa...

海岛Blog 913

ACboy needs your help again!(queue入门)

ACboy needs your help again!题目:分析:代码: 题目: ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17302 Accepted Submis...

Stone 不会喝水的博客 536

HDOJ 1702 ACboy needs your help again!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 351

MummyDing's Blog 1146

hdu1702ACboy needs your help again!(栈和队列的简单应用)

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3508    Accepted Submission(s): 1794 Problem Description A

千言万语ROOM 429

HDU 1702 ACboy needs your help again! (栈和队列的模拟)

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3164Accepted Submission(s): 1655 Problem Description AC...

136

【杭电oj】1702 - ACboy needs your help again!(栈和队列)

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

wyg1997 572

HDU 1702 ACboy needs your help again! (栈与队列)

栈与队列的模拟

大咸鱼。。。 813

A - ACboy needs your help again! (栈和队列的简单运用)

点击打开链接 A - ACboy needs your help again!   #include #include #include #include #include using namespace std; void sta1(int n) { int a; stack o; while(n--) { char num[6]

Dream__For__You的博客 593
上一篇: River Hopscotch(二分)
下一篇: Rails(栈和队列简单应用)
Oenheng
博客等级 码龄10年 7粉丝 111原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值