<OFFER05> 05_ReplaceSpaces
void ReplaceBlank(char str[], int length) // length >= the real length of string
{
if (str == nullptr || length <= )
{
return;
}
int origin_str_len = ;
int new_str_len = ;
int i = ;
int count_space = ;
while (str[i] != '\0')
{
if (str[i] == ' ')
++count_space;
++origin_str_len;
++i; }
new_str_len = origin_str_len + * count_space;
if (new_str_len > length)
return; while (origin_str_len >= && new_str_len > origin_str_len)
{
if (str[origin_str_len] == ' ')
{
str[new_str_len--] = '';
str[new_str_len--] = '';
str[new_str_len--] = '%'; }
else
{
str[new_str_len--] == str[origin_str_len];
}
--origin_str_len;
} }
<OFFER05> 05_ReplaceSpaces的更多相关文章
- 【算法训练营day8】LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58-II. 左旋转字符串
[算法训练营day8]LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58- ...
- 剑指Offer05 用栈模拟队列
添加了模板类应用 /************************************************************************* > File Name: ...
随机推荐
- 字符编码笔记:ASCII,Unicode和UTF-8(转载)
注:我注释的地方有 add by zhj.另Unicode.UTF-8.GB2312查询http://www.2fz1.com/so/ 在python中,a.decode(xxx)就是把str类型的字 ...
- TortoiseGit密钥的配置(转)
add by zhj:说到密钥,就不得不提非对称加密.目前使用最广泛的非对称加密算法是rsa,它是美国三位科学家于1977年发明的. 一对密钥对有两个密钥,其中一个为私钥,一个为公钥,两者没有什么区别 ...
- 【JS】自学
JS自学网址: http://www.runoob.com/js/js-tutorial.html
- Java学习之路-RMI学习
Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程序编程接口.它使客户机上运行的程序可以调用远 ...
- [vue]vue v-on事件绑定(原生修饰符+vue自带事件修饰符)
preventDefault阻止默认行为和stopPropagation终止传递 event.preventDefault() 链接本来点了可以跳转, 如果注册preventDefault事件,则点了 ...
- PAT Maximum Subsequence Sum[最大子序列和,简单dp]
1007 Maximum Subsequence Sum (25)(25 分) Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A ...
- soapUI-Conditional Goto
1.1.1 Conditional Goto 1.1.1.1 概述 - Conditional Goto Conditional Goto TestStep包含任意数量的XPath/JSONPath ...
- [LeetCode] 589. N-ary Tree Preorder Traversal_Easy
Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary ...
- isKindOfClass isMemeberOfClass 的区分
isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...
- HDU 4500 小Q系列故事——屌丝的逆袭(简单题)
http://acm.hdu.edu.cn/showproblem.php?pid=4500 AC代码: #include<math.h> #include<stdio.h> ...