#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution {
public:
void ReplaceBlank(char s[],int length) {
if (length == 0) return;
int count = 0, num = 0;
while (s[num]!='\0')
{
if (s[num] == ' ') count++;
num++;
}
int p = num - 1, q = num - 1 + 2 * count;
while (p >= 0&&p < q) {
if (s[p] != ' ') {
s[q] = s[p];
p--;
q--;
}
else {
s[q--] = '%';
s[q--] = '0';
s[q--] = '2';
p--;
}
}
}
};
int main()
{
Solution s;
char l[100] = {' ','W','e',' ','a','r','e',' ',' h','a','p','p','y','.',' ',' '};
cout << l << endl;
s.ReplaceBlank(l,100);
cout << l << endl;
return 0;
}
剑指offer5
最新推荐文章于 2024-03-19 10:30:28 发布