class Solution {
public:
void replaceSpace(char *str,int length) {
int new_length = 0;
int space = 0;
char* start = str;
while (*start != '\0')
{
if (*start == ' ')
{
space++;
}
start++;
}
new_length = length + 2 * space;
int end1 = length - 1;
int end2 = new_length - 1;
while (end1 != end2)
{
if (str[end1] != ' ')
{
str[end2--] = str[end1--];
}
else
{
str[end2--] = '0';
str[end2--] = '2';
str[end2--] = '%';
end1--;
}
}
}
};