我試圖通過維護空格來顛倒句子中的單詞順序,如下所示。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