#include"string.h"
#include<iostream>
using namespace std;
void ReplaceBlank(char str[])
{
if (strlen(str) == 0)
return;
//find num of blank
int NumOfBlank = 0;
for (int i = 0; i < strlen(str); i++)
{
if (str[i] == ' ')
NumOfBlank++;
}
int j = strlen(str) + NumOfBlank * 2;
int i = strlen(str) - 1;
str[j--] = '\0';
while (i >= 0)
{
if (str[i] == ' ')
{
str[j--] = '0';
str[j--] = '2';
str[j--] = '%';
}
else
{
str[j--] = str[i];
}
i--;
}
return;
}
int main()
{
char b[50] = { " " };
ReplaceBlank(b);
return 0;
}
剑指offer || 03_replaceBlank
最新推荐文章于 2022-07-17 08:46:00 发布