剑指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;
}
}
