回 帖 发 新 帖 刷新版面

主题:Anagrams by Stack

Time limit: 1 Seconds   Memory limit: 32768K   
Total Submit: 5340   Accepted Submit: 1761   

--------------------------------------------------------------------------------

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 o is 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
]

请用C++编程,答案发送E_MAIL:264681137@qq.com,谢谢大家帮忙!!!!![em14]

回复列表 (共3个回复)

沙发

请问你知道是什么错误吗?

[C++ Error] sysmac.H(37): E2209 Unable to open include file ''windows.h''

板凳

老师:
在 borland c++ bulder6.0中运行程序出现以下错误是什么原因,请指教。

[C++ Error] sysmac.H(37): E2209 Unable to open include file ''windows.h''
[C++ Error] sysmac.H(54): E2092 Storage class ''inline'' is not allowed here
[C++ Error] sysmac.H(54): E2141 Declaration syntax error
[C++ Error] sysmac.H(67): E2190 Unexpected }
[C++ Error] guiddef.h(146): E2209 Unable to open include file ''string.h''
[C++ Error] guiddef.h(161): E2268 Call to undefined function ''memcmp''
[C++ Error] sysmac.H(147): E2209 Unable to open include file ''unknwn.h''
[C++ Error] sysmac.H(160): E2303 Type name expected
[C++ Error] sysmac.H(281): E2257 , expected
[C++ Error] sysmac.H(299): E2147 ''HINSTANCE'' cannot start a parameter declaration
[C++ Error] sysmac.H(300): E2147 ''HINSTANCE'' cannot start a parameter declaration
[C++ Error] sysmac.H(301): E2147 ''HINSTANCE'' cannot start a parameter declaration
[C++ Error] sysmac.H(302): E2147 ''HINSTANCE'' cannot start a parameter declaration
[C++ Error] System.hpp(124): E2141 Declaration syntax error
[C++ Error] dstring.h(14): E2209 Unable to open include file ''stdarg.h''
[C++ Error] dstring.h(35): E2293 ) expected
[C++ Error] dstring.h(39): E2293 ) expected
[C++ Error] dstring.h(50): E2303 Type name expected
[C++ Error] dstring.h(56): E2303 Type name expected
[C++ Error] dstring.h(168): E2451 Undefined symbol ''NULL''
[C++ Error] wstring.h(11): E2209 Unable to open include file ''wtypes.h''
[C++ Error] wstring.h(14): E2209 Unable to open include file ''stdarg.h''
[C++ Error] wstring.h(53): E2293 ) expected
[C++ Error] wstring.h(77): E2303 Type name expected
[C++ Error] wstring.h(77): E2139 Declaration missing ;
[C++ Error] wstring.h(77): E2228 Too many error or warning messages

wtf?

3 楼

工程建设错误,应该是非控制台形式.

我来回复

您尚未登录,请登录后再回复。点此登录或注册