zoj 1004 Anagrams by Stack (回溯)

开始觉得无从下手啊 毕竟自己是个菜鸟....

用递归,回溯法

程序写的有点乱,主要是变量命名时没有什么规则,让人看不懂,自己也懒得修改了, 注释也有点不清楚......

原题:

How can anagrams result from sequences of stack operations? There are two sequences of stack operators which can convert TROT to TORT:

[
i i i i o o o o
i o i i o o i o
]

where i stands for Push and o stands for Pop. Your program should, given pairs of words produce sequences of stack operations which convert the first word to the second.

Input

The input will consist of several lines of input. The first line of each pair of input lines is to be considered as a source word (which does not include the end-of-line character). The second line (again, not including the end-of-line character) of each pair is a target word. The end of input is marked by end of file.

Output

For each input pair, your program should produce a sorted list of valid sequences of i and o which produce the target word from the source word. Each list should be delimited by

[
]

and the sequences should be printed in "dictionary order". Within each sequence, each i and o is followed by a single space and each sequence is terminated by a new line.

Process

A stack is a data storage and retrieval structure permitting two operations:

Push - to insert an item and
Pop - to retrieve the most recently pushed item

We will use the symbol i (in) for push and o (out) for pop operations for an initially empty stack of characters. Given an input word, some sequences of push and pop operations are valid in that every character of the word is both pushed and popped, and furthermore, no attempt is ever made to pop the empty stack. For example, if the word FOO is input, then the sequence:

i i o i o ois valid, but
i i o is not (it's too short), neither is
i i o o o i(there's an illegal pop of an empty stack)

Valid sequences yield rearrangements of the letters in an input word. For example, the input word FOO and the sequence i i o i o o produce the anagram OOF. So also would the sequence i i i o o o. You are to write a program to input pairs of words and output all the valid sequences of i and o which will produce the second member of each pair from the first.

Sample Input
madam
adamm
bahama
bahama
long
short
eric
rice

Sample Output
[
i i i i o o o i o o 
i i i i o o o o i o 
i i o i o i o i o o 
i i o i o i o o i o 
]
[
i o i i i o o i i o o o 
i o i i i o o o i o i o 
i o i o i o i i i o o o 
i o i o i o i o i o i o 
]
[
]
[
i i o i o i o o 
]
程序:

 

内容概要:本文全面介绍了数据流图(DFD)的概念、构成元素及其重要性。数据流图是从数据传递和加工的角度,以图形方式表达系统逻辑功能、数据流向和变换过程的工具。文章详细解释了数据流图的四个基本元素:数据流、加工、数据存储和外部实体,并通过实例说明了这些元素在实际场景中的应用。文中强调了数据流图在软件开发需求分析和业务流程优化中的关键作用,通过绘制顶层、中层和底层数据流图,逐步细化系统功能,确保数据流向和处理逻辑的清晰性。此外,文章还指出了常见绘制误区及解决方法,并以在线购物系统为例进行了实战分析,展示了从需求分析到数据流图绘制的全过程。 适合人群:软件工程师、业务分析师、系统设计师以及对系统分析与设计感兴趣的初学者。 使用场景及目标:①帮助开发团队在需求分析阶段清晰展示数据流动和处理过程,避免理解偏差;②辅助企业梳理和优化业务流程,识别效率低下的环节,提升运营效率;③为系统设计和开发提供详细的逻辑框架,确保各模块的功能明确,减少开发错误。 阅读建议:本文内容详实,涵盖了从理论到实践的各个方面。建议读者在学习过程中结合实际项目背景,逐步掌握数据流图的绘制技巧,并通过反复练习和优化,加深对系统分析与设计的理解。
资源下载链接为: https://pan.quark.cn/s/5c50e6120579 《CoffeeTime_0.99.rar:主板BIOS修改工具详述》 在计算机硬件领域,BIOS(基本输入输出系统)是计算机启动时最先加载的软件,它负责初始化硬件设备,并为操作系统提供基本的交互功能。不过,随着处理器技术的持续进步,部分主板可能无法原生支持更新的CPU型号。为解决这一问题,一些技术爱好者和专业人士会通过修改主板BIOS,也就是俗称的“魔改”,来提升其兼容性。本文将深入剖析名为“CoffeeTime_0.99.rar”的工具,它是一款专门用于主板BIOS修改,以实现对第6、7、8、9代英特尔CPU支持的工具。 我们先来看“CoffeeTime.exe”,这是该工具的主程序文件。通常情况下,它会配备一套直观易用的用户界面,方便用户对BIOS进行修改操作。不过,在使用该工具之前,用户必须具备一定的电脑硬件知识,因为一旦操作失误,就可能导致系统运行不稳定,甚至无法启动。对于初学者而言,谨慎操作至关重要,否则可能会造成不可挽回的损失。 “readme.txt”是软件包中常见的文档,一般会包含使用指南、注意事项以及开发者提供的其他重要信息。在使用CoffeeTime之前,用户务必要仔细阅读该文件,因为里面可能包含了如何正确运行程序、避免错误操作以及解压后具体步骤等关键内容。 “bin”和“data”是两个文件夹,它们可能包含了用于BIOS修改的各种二进制文件和数据。“bin”文件夹通常会包含特定版本的BIOS固件或用于修改的工具,而“data”文件夹则可能包含更新CPU微码、识别信息等必要的数据文件。在进行BIOS修改的过程中,这些文件会被程序调用,从而实现对原有BIOS的扩展或修正。 BIOS的修改过程一般包含以下步骤:首先,备份原始BIOS,这是在进行任何修改前的必要步骤,以便
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值