我试图通过维护空格来颠倒句子中的单词顺序,如下所示。C++中的字符串反转
[this is my test string] ==> [string test my is this]
我确实在一步步的方式,
[this is my test string] - input string
[gnirts tset ym si siht] - reverse the whole string - in-place
[string test my is this] - reverse the words of the string - in-place
[string test my is this] - string-2 with spaces rearranged
是否有任何其他的方法来做到这一点?是否有可能在现场做最后一步?
我很想知道这背后的商业逻辑... – jcolebrand 2010-09-23 17:32:23
@drachenstern嗯,你可能呈现双向文本时需要类似的算法。 – ybungalobill 2010-09-23 17:36:37
你是什么意思你的“是否也可以做最后一步就地”?你有什么已经在做一切就地。你在说什么“最后一步”? – AnT 2010-09-23 17:38:37