首页 > 试题广场 >

空格替换

[编程题]空格替换
  • 热度指数:59890 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

给定一个string iniString 及其长度 int len, 已知该字符串中有空格,现要求编写程序将字符串中空格替换为“%20”。返回更改后的string。假设该字符串有足够的空间存放新增的字符,并且知道原字符的长度(小于等于1000),同时保证字符串由大小写的英文字母组成。

示例1

输入

"Mr John Smith",13

输出

"Mr%20John%20Smith"
示例2

输入

"Hello  World",12

输出

"Hello%20%20World"
头像 杨~~
发表于 2022-01-21 16:30:44
public: string replaceSpace(string iniString, int length) { // write code here string s=""; for(int i=0;i<length;i++){ 展开全文
头像 等一个天亮
发表于 2021-10-14 17:30:48
import java.util.*; public class Replacement { public String replaceSpace(String iniString, int length) { // write code here retu 展开全文
头像 牛客702786295号
发表于 2021-11-09 15:02:47
class Replacement:     def replaceSpace(self, iniString, length):        &n 展开全文
头像 Jorunnaparva
发表于 2020-10-07 09:01:36
class Replacement { public: string replaceSpace(string iniString, int length) { // count zeros int last = length + 2 * count(iniSt 展开全文
头像 爱编程的宽宽
发表于 2023-04-14 12:47:52
class Replacement { public: string replaceSpace(string iniString, int length) { // write code here string ret; // 创建一个接收返回值的字符串 展开全文
头像 牛客314328168号
发表于 2023-02-10 22:58:55
class Replacement { public: string replaceSpace(string iniString, int length) { // write code here string res = ""; for(au 展开全文