#include <iostream>
using namespace std;
class Solution {
public:
void replaceSpace(
char *
str,
int length){
int blankNumber =
0;
int oldstringLen;
for (oldstringLen =
0;
str[oldstringLen] !=
'\0'; oldstringLen++){
if (
str[oldstringLen] ==
' ')
blankNumber++;
}
int newstringLen = oldstringLen + blankNumber *
2;
if (newstringLen>length)
return;
str[newstringLen] =
'\0';
int point1 = oldstringLen -
1, point2 = newstringLen -
1;
while (point1 >=
0 && point2>point1){
if (
str[point1] ==
' '){
str[point2--] =
'0';
str[point2--] =
'2';
str[point2--] =
'%';
}
else
str[point2--] =
str[point1];
point1--;
}
}
};
转载请注明原文地址: https://ju.6miu.com/read-16216.html