剑指offer经典题
#include<stdio.h>
#include<iostream>
using namespace std;
void ReplaceBlank(char string[], int capacity)
{
if (string == NULL || capacity <= 0)
return;
int i= 0;
int stringLength = 0;
int blanknumber = 0;
while (string[i] != '\0')
{
++stringLength;
if (string[i] == ' ')
{
++blanknumber;
}
++i;
}
int newStrLength = stringLength + blanknumber * 2;
if (newStrLength > capacity)
return;
int p1 = stringLength;
int p2 = newStrLength;
while (p1>=0&&p2>p1)
{
if (string[p1] == ' ')
{
string[p2--] = '0';
string[p2--] = '2';
string[p2--] = '%';
}
else
{
string[p2]= string[p1];
p2--;
}
--p1;
}
}
![这里写图片描述](https://img-blog.csdn.net/20180307183628125?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZGF4eW0=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)