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 mar

这篇博客介绍了一个利用堆栈操作将单词TROT转换为TORT的方法,并探讨如何从源词生成目标词的合法序列。文章提供了输入输出示例,并说明了堆栈的push(入栈)和pop(出栈)操作。作者提到,对于每个输入词对,程序需要输出所有能将第一个词转换成第二个词的有序i和o序列,且序列由换行符分隔。样例输入和输出展示了该问题的解决方案,并指出可以使用递归思想来解决这个问题。
最低0.47元/天 解锁文章
579

被折叠的 条评论
为什么被折叠?



