Переворот строки в 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

Есть ли другой способ сделать это? Можно ли также выполнить последний шаг на месте?

7
задан josh 23 September 2010 в 17:29
поделиться