char* replaceSpace(char* s ) {
int len1 = strlen(s);
int count = 0;
for(int i=0; i<len1; i++){
if(s[i] == ' ')
count++;
}
int len2 = len1+2*count;
char* str = (char*)malloc(len2);
int j=0;
for(int i=0; i<len1; i++){
if(s[i] == ' '){
str[j++] = '%';
str[j++] = '2';
str[j++] = '0';
}
else{
str[j++] = s[i];
}
}
return str;
}
void replaceSpace(char *str,int length) {
if(str==nullptr || length==0)
return;
char* p = str;
int count = 0;
while(*p != '\0'){
if(*p == ' ')
count++;
p++;
}
char* end1 = str+length-1;
char* end2 = str+length+2*count-1;
while(end1 != end2){
if(*end1 != ' '){
*(end2--) = *(end1--);
}
else{
*(end2--) = '0'; //注意:从后向前替换
*(end2--) = '2';
*(end2--) = '%';
end1--;
}
}
}