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/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 14 Accepted Submission(s) : 10
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
2007省赛集训队练习赛(1)

堆栈的简单应用
题意:给出一组命令,"FIFO"代表下面的命令先进先出,"FILO"代表后进先出,(IN代表进,out代表出)
      求输出命令是OUT时输出的数,若此时为空则输出None
题解:堆栈的简单应用,在比较命令时如"FIFO" or "FILO"可比较其中同一位置不同的字符ch[2]
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
int main()
{
    int cases,n,tmp;
    char ch[10];
    scanf("%d",&cases);
    while(cases--)
    {
        scanf("%d %s",&n,ch);
        if(ch[2]=='F')
        {
            queue<int>Q;
            while(n--)
            {
                scanf("%s",ch);
                if(ch[0]=='I')
                {
                    scanf("%d",&tmp);
                    Q.push(tmp);
                }
                else if(!Q.empty())
                {
                    printf("%d\n",Q.front());
                    Q.pop();
                }
                else
                    printf("None\n");
            }
        }
        else
        {
            stack<int>S;
            while(n--)
            {
                scanf("%s",ch);
                if(ch[0]=='I')
                {
                    scanf("%d",&tmp);
                    S.push(tmp);
                }
                else if(!S.empty())
                {
                    printf("%d\n",S.top());
                    S.pop();
                }
                else
                    printf("None\n");
            }

        }
    }
    return 0;
}



CentOS 7下Apache+PHP-FPM多PHP版本共存实战 PHP多版本共存是LAMP架构中保障遗留系统兼容性与新特性演进的关键技术方案。其核心原理在于解耦Web服务器与PHP执行环境,通过FastCGI协议实现请求路由与进程隔离。Apache的mod_proxy_fcgi模块配合PHP-FPM的多池化管理,支持按虚拟主机或子目录精准绑定不同PHP解释器,天然规避mod_php单版本硬绑定缺陷。该方案显著提升运维安全性(如老版本限权运行)、资源可控性(独立pm配置)及灰度升级能力,广泛应用于金融、政务等需长期维护多代PHP应用的生产环境。本文聚焦CentOS 7平台 阅读详情

相关推荐

蓝牙Mesh安全机制全解析:如何防止你的智能门锁被黑客控制?

本文深入解析蓝牙Mesh安全机制,重点探讨如何保护智能门锁免受黑客攻击。详细介绍了蓝牙Mesh的多层次安全架构,包括密钥管理体系、设备入网流程及实战防护策略,帮助用户构建更安全的智能家居网络。

h3i4j的博客 736

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

【从零开始玩量化1】AKShare: Python开源财经数据接口库

文章目录量化的第一步:数据AKShare介绍AKShare安装AKShare使用AKTools安装/使用结语 量化的第一步:数据 想要玩量化,第一步要有数据,这个数据可能是历史交易数据、财务数据、宏观数据等等。我们最终要做的,无非就是从数据中分析出有价值的信息,以便用来指导投资策略。 在获取数据的这条道路上,我走了很多弯路,尝试了各种方法:使用Tushare到放弃、自己写网易股票页面的爬虫,自己写申万行业数据的爬虫、自己写同花顺问财的爬虫、使用聚宽的免费数据API等等,直到最终,我发现了AKShare。 A

量化投资助手的博客 5万+

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

南邮-软件设计实验(C++版)

南邮软件设计 A档 一、分数统计 课题内容:   设计一个分数统计程序。包括学生信息的输入输出以及排序。通过该课题全面熟悉数组、字符串、文件的使用,掌握程序设计的基本方法及友好界面的设计。 课题要求: (1)输入某班级学生的姓名、分数; (2)对(1)的分数进行降幂排列并输出; (3)具有输入输出界面。 示例代码: #include<bits/stdc++.h> using...

Dainelcw 1万+

SAP Fiori Launchpad 自定义层文本翻译实战:精准修正 Tile、Catalog 与 Group 标题

SAP Fiori 项目中,入口层(tile/catalog/group)的翻译问题常被忽视,但其直接影响用户体验。与前端i18n不同,这些文本属于平台配置数据,需通过ABAP标准翻译流程(SE63)处理。关键步骤包括:使用/UI2/FLC定位Text ID和Configuration ID,根据前缀区分Main/Property WD Config Key,在SE63中锁定WDY_CONF_USERT2表对象进行翻译。操作时需注意使用系统源语言环境,翻译完成后可能需要清理缓存。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 184

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

Dify 第 2 篇 Dify 插件离线安装

Dify是一个支持插件扩展的AI平台,其插件市场提供5种类型插件(模型、工具、Agent策略、扩展、插件包)。由于默认pip安装速度慢,可通过dify-plugin-repackaging工具将插件转换为离线包(使用阿里云镜像加速)。该工具提供两种方式:1)自备Python环境执行脚本;2)使用Docker环境(推荐)。脚本支持从Dify市场或GitHub下载插件,并重新打包为含依赖的离线包,便于通过"本地插件"方式快速安装。

甘蓝的专栏 1286

【题解】HDU 1702 ACboy needs your help again!

目录 题目描述 题意分析                                                                                                                     题目描述 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768...

飒然霜林的博客 356

LoRA 完整解析:从理论到实践

LoRA(低秩适应)是一种高效的大模型微调方法,通过添加少量可训练参数(低秩矩阵)来适配新任务,避免全参数微调的高成本。其核心是将权重更新ΔW分解为两个小矩阵B×A的乘积,大幅减少训练参数量(仅0.1-1%)。LoRA基于内在维度假设,通过低秩约束捕捉核心任务信息,兼具效率与效果。实际应用中,常用配置为秩r=16-32,目标模块选择注意力层的q_proj和v_proj,学习率比全参数微调大10倍(约1e-4)。优势包括参数高效(内存降低60-80%)、多任务适配灵活、保留预训练知识等,已成为大模型微调的主流

echo的博客 1425

汽车UDS诊断之诊断会话控制服务(0x10)深度剖析

DiagnosticSessionControl就是诊断会话控制。 请求消息定义 A_Data类型 参数名称 Cvt 字节值 助记符 #1 诊断会话控制请求SID M 0x10 DSC #2 子功能=[诊断会话类型] M 0x00-0xFF LEV_DS_ ...

心骗小白话的博客 7424

HDU-1702 ACboy needs your help again!【栈与队列】

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 ACb

不忘初心,知行统一 404

【导航理论&实战篇】四足机器人弹簧倒立摆(SLIP)动力学模型

认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长!本文先对四足机器人动力学模型-VMC、SLIP和浮动机体模型做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章四足机器人弹簧加载倒立摆(SLIP)动力学模型是一种用于描述和分析四足机器人在运动过程中动态特性的理论模型。这种模型将四足机器人的腿部简化为弹簧,而机器人的身体则被视为一个倒立摆,这样的抽象使得研究者能够更容易地分析和控制机器人的运动。提示:以下是本篇文章正文内容。

qq_35635374的博客 809

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

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

Bearing in mind forever! 734

全球国家地区城市数据

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

HDU1702:ACboy needs your help again!(栈和队列的应用)

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 A

qq_35634181的博客 277

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

HDU1702 ACboy needs your help again! (栈和队列)

题目链接:hdu1702 题意:模拟堆栈和队列过程。FIFO就是先进先出(队列),FILO就是先进后出(堆栈)。 code: #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; string method, str; ...

江小举的博客 444

HDU 1702 ACboy needs your help again! 【栈+队列】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702 思路:模拟题,大家看下代码就会了,刚开始我也是一头雾水,看来下大佬的代码感觉~嘿~嘿~嘿【栈和队列的最基本的应用】代码如下: #include&lt;bits/stdc++.h&gt; //栈和队列的最基本的应用 #include&lt;algorithm&gt; using nam...

甜晨流年 293

【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

雄英通信站 345

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

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): 5685    Accepted Submission(s): 2973 Problem Description

Oenheng的博客 1363

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

x311609001028的博客 446

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

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 o

就是乐 451

C - 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

qq_43233736的博客 327

ACboy needs your help again!(简单栈)

简单栈和队列的应用

杰兰特 498
上一篇: 看病要排队(优先队列priority_queue)
下一篇: 简单计算器
fanlinqiang
博客等级 码龄15年 103粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值