[剑指offer 编程题]替换空格
替换空格
http://www.nowcoder.com/questionTerminal/4060ac7e3e404ad1a894ef3e17650423
class Solution {
public:
void replaceSpace(char *str,int length) {
string str_2 = "";
int plus_length = 0;
for(int i = 0;i<length;i++){
if(str[i] != ' '){
str_2 += str[i];
}
else {
str_2 += "%20";
plus_length += 2;
}
}
length += plus_length;
for(int j = 0;j<length;j++){
str[j] = str_2[j];
}
}
}; 