class Replacement {
public:
string replaceSpace(string iniString, int length) {
// write code here
if (length == 0)
return iniString;
int lenOfspace = 0;
for (int i = 0 ; i< length; i++)
if (iniString[i] == ' ')
lenOfspace++;
int len = lenOfspace*2+length;
string result;
result.resize(len);
int j = 0;
int i = 0;
while (i<len&&j<length)
{
if (iniString[j] == ' ')
{
result[i++] = '%';
result[i++] = '2';
result[i++] = '0';
}
else
result[i++] = iniString[j];
j++;
}
return result;
}
//收藏此位作者的答案 http://www.nowcoder.com/profile/408620
};
空格替换2
最新推荐文章于 2024-02-12 18:10:33 发布