HDU 1702 ACboy needs your help again!(单链表写法)

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

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

题意描述: FILO先进后出,FIFO先进先出。

解题思路: 如果是FILO用为头插法建立链表,见到OUT就输出,如果是FIFO用尾插法建立链表,见到OUT就输出。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
	int data;
	struct node *next;
 } ;
 
 typedef struct node *LinkList;
 
 void wc(LinkList head,int n)//尾插法建立单链表
 {
 	LinkList p,rear=head;
 	char a[10];
 	int b;
 	for(int i=1;i<=n;i++)
 	{
 		scanf("%s",a);
 		if(a[0]=='I')
 		{
		 	p=(node *)malloc(sizeof(node));
 			scanf("%d",&b); 
 			p->data=b;
 			rear->next=p;
 			rear=p; 
		}
		rear->next=NULL;
		p=head->next;
		if(a[0]=='O')
		{
			p=head->next;
			if(p==NULL)
				printf("None\n");
			else
			{
				printf("%d\n",p->data);
				head=head->next;
			}
			
		}
	}
 }
 
 void tc(LinkList head,int n)//头插法建立单链表
 {
 	LinkList p;
 	char a[10];
 	int b;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a);
		if(a[0]=='I')
		{
			p=(node *)malloc(sizeof(node));
			scanf("%d",&b);
			p->data=b;
			p->next=head->next;
			head->next=p;
		}
		if(a[0]=='O')
		{
			p=head->next;
			if(p==NULL)
				printf("None\n");
			else
			{
				printf("%d\n",p->data);
				head=head->next;
			}
		
		}
	}
 }
 
 int main(void)
 {
 	LinkList head;
 	int n; 
 	char a[110],b[10];
 	int t;
 	scanf("%d",&t);
	 while(t--)
 	{
	 	scanf("%d",&n);
	 	getchar();
 		scanf("%s",b);
		if(b[2]=='F')
		{
			head=(node *)malloc(sizeof(node));
			head->next=NULL;
			wc(head,n);
		}	
		if(b[2]=='L')
		{
			head=(node *)malloc(sizeof(node));
			head->next=NULL;
			tc(head,n);	
		}	
	}
	return 0;
 }
国央企创新负责人如何通过平台实现科研成果的快速识别与转化?.docx 科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

相关推荐

PotPlayer自用皮肤

自用 PotPlayer 皮肤,仅微调了字体大小与颜色,是按个人习惯调整,未做适配性调整。

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

windows10系统上安装最新版mysql 8.0详细步骤

windows10系统上安装最新版mysql 8.0详细步骤

glei20的博客 6715

ACboy was kidnapped!!

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

diantong4414的博客 591

从调节阀到步进电机:图解位置型PID与增量式PID的核心区别

本文深入解析了位置型PID与增量式PID的核心区别。通过调节阀和步进电机的实例,阐明位置式PID输出绝对位置,适用于直接控制执行机构;而增量式PID输出位置变化量,天然支持无扰动切换,更适合步进电机等场景。文章重点剖析了增量式PID在系统安全与平滑切换方面的关键优势。

weixin_29051811的博客 357

大模型运维实战:从GPU选型到推理服务稳定落地

大模型服务进入生产环境后,运维对象从传统进程转向GPU显存、KV Cache、推理吞吐等动态资源。显存利用率、首token延迟、并发队列深度等指标,直接影响模型服务的质量与成本。理解推理框架的内存分配机制、掌握监控告警与自动化扩容手段,是保障服务稳定的关键。这类能力广泛应用于企业私有化部署、智能客服、知识库问答等场景,帮助运维团队从被动救火转向主动容量规划与性能调优。本文围绕大模型运维的完整路线,梳理从硬件选型、推理部署到监控排障的实战经验,并算清一份真实项目的长期成本账。

weixin_29054245的博客 238

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的博客 444

LabVIEW状态机实战:用STM32+DHT11搭建温湿度监测系统(附完整VI源码)

本文详细介绍了如何利用LabVIEW状态机模式与STM32微控制器、DHT11温湿度传感器构建温湿度监测系统。通过硬件选型、状态机设计、LabVIEW程序实现及系统优化等环节,提供了一套完整的解决方案,并附有VI源码,助力开发者快速实现嵌入式温湿度监测应用。

weixin_42549723的博客 519

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

frtgbhyu的博客 243

YOLOv12创新改进 | 全网独家创新篇、小目标检测改进 | AAAI 2025 | 引入HS-FPN中的HFP和SDP创新点,从频域增强小目标特征,淘汰FPN进行升级,助力YOLOv12有效涨点

本文提出了HS-FPN(高频和空间感知特征金字塔网络),通过HFP(高频感知)模块增强小目标特征,SDP(空间依赖感知)模块捕获像素间空间依赖关系。实验在AI-TOD等小目标数据集上验证了该方法的有效性,相比FPN显著提升检测性能。文章详细介绍了HS-FPN的网络结构、核心代码实现及在YOLOv12中的应用方法,并提供多种改进版本的yaml配置文件,为小目标检测任务提供了有效的解决方案。

Ai缝合怪、助力小伙伴高效发论文 336

图像处理入门007:图像处理中的数学基础:线性代数与卷积

一种:把 OpenCV 当黑盒,调用,效果不对就乱调参数;另一种:理解每个像素是怎么被周围邻域"加权平均"的,理解核翻转、边界填充、stride 的含义。前者能干活,后者能解难题。一旦遇到自定义核(比如 ISP 上的锐化)、深度学习反向传播、医学图像重建,你就必须把卷积、相关、矩阵乘法这些基本功捡回来。线性代数三件套:向量点积、矩阵乘法、线性变换;2D 卷积的数学定义:核翻转、滑动窗口、边界填充。并手写一个,验证它与和的结果完全一致(误差 < 1e-9)。f∗gn∑m−∞∞f。

专注:太空算力、AI infra、异构调度、大模型成本工程 386

暑期集训之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 monst

进击的小白 250

【AI智能体】QClaw 对接GitHub处理自动化任务实战操作详解

QClaw 对接GitHub处理自动化任务实战操作详解

congge 4869

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的博客 444

QGraphicsView通过鼠标操作来绘制图元

在Visio和MindManager等类似的图元操作软件中,很多时候我们会通过鼠标操作来添加自定义的图元。这里就介绍一下如何在QT的图形视图框架中通过鼠标绘制来添加图元。

yang1fei2的博客 3576

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

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 :(. As a smart ACMer, you want to get ACboy out of the monster's l

To-nemy 450

NTscan扫描工具

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

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

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

HDU1702 acm 数据结构 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

Little_boy_z的博客 464

ACboy(队列和栈的基础操作)

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 monst

Sirius_han的博客 683

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

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

辞树 469

【一只蒟蒻的刷题历程】 【HDU-1702】 ACboy needs your help again!

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 ????. As a smart ACMer, you want to get ACboy out of the monster’s labyrinth.But when yo

黑桃 284

HDU-ACboy needs your help again!-1702

栈和队列的应用,栈是先进后出,队列是先进先出。 ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2594    Accepted Submission(s): 1344

灰色头像不会再跳动 626

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 ACb

ACM!荣耀之路! 2328
上一篇: Shuffle Card
下一篇: HDU 1829 A Bug's Life
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值