Problem
把字符串中的空格替换为%20
Solution
主要看C++中char *的用法吧
void replaceSpace(char *str,int length) {
int cnt = 0;
for (int i = 0; i < length; i++) {
if (str[i] == ' ')
cnt++;
}
for (int i = length - 1; i >= 0; i--) {
if (str[i] != ' ')
str[i + 2 * cnt] = str[i];
else {
str[i + 2 * cnt] = '0';
str[i + 2 * cnt - 1] = '2';
str[i + 2 * cnt - 2] = '%';
cnt--;
}
}
}