(2) You are not allowed to apply for a new space.
(3) spaces, tabs, and blank lines are not allowed at the beginning and end of the processed string.
(4) If the original string contains consecutive spaces and horizontal tabs, only one space is required for the processed string.
(5) If the original string contains consecutive spaces, horizontal tabs, and empty rows, the processed string only needs to store one empty row.
Changed after Reminder ):
remove_extra_space (* state =;
i =;
j =;
(; str [i]! =; ++ (str [i] == || str [i] == (state == || state == || state == (state == str [j ++] = state = (str [i] == (state == || state == (state == str [j-] = state = (state == str [j ++] = state =
str [j ++] = state = (state == || state ==-str [j] =}
Refer to the idea and playerc code to use pointer version (recommended):
remove_extra_space (* * sp = * prev =
(* str && (* str == || * str == || * str == ++
(; * str; ++ (*: * str = (* prev == || * prev ==
(* prev == (* prev == * prev =
prev = * sp ++ = *
(prev && * prev && (* prev == || * prev ==-* sp =}
Refer to the code written by playerc: http://www.cnblogs.com/playerc/p/3217355.html
Finally, thank you to all the friends who provided valuable advice!