剑指Offer面试题2:替换空格
来源:互联网 发布:硬盘分区后数据恢复 编辑:程序博客网 时间:2024/06/07 16:58
如书中介绍实现
#include<iostream>using namespace std;void replaceblank(char sentence[],int length,int orilen, int blalen){ if (sentence == NULL || length <= 0) return; int p1=orilen; int p2=orilen+2*blalen; if(p2>length) return; while (p1!=p2) { if(sentence[p1]!=' ') sentence[p2--]=sentence[p1--]; else{ sentence[p2--]='0'; sentence[p2--]='2'; sentence[p2--]='%'; --p1; } }}int main(){ char sentence[100] = "We Are Happy."; int orilength = 0; int blalength = 0; while(sentence[orilength]!='\0') { if(sentence[orilength]==' ') ++blalength; ++orilength; } cout<<sentence<<endl; replaceblank(sentence,sizeof(sentence),orilength,blalength); cout<<sentence<<endl;}
0 0
- 剑指Offer面试题2:替换空格
- 剑指offer-->面试题4 替换空格
- 《剑指offer》面试题4 替换空格
- 【剑指offer】面试题4:替换空格
- 【剑指offer】面试题4替换空格
- 剑指offer 面试题4 替换空格
- 剑指Offer:面试题4 替换空格
- 剑指offer-面试题4-替换空格
- 《剑指Offer》面试题4:替换空格
- 【剑指offer】 面试题4: 替换空格
- 剑指offer 面试题4---替换空格
- 剑指offer面试题4-- 替换空格
- 《剑指Offer》面试题:替换空格
- 【剑指offer】面试题4:替换空格
- 剑指Offer:面试题4 替换空格
- 剑指offer-面试题4:替换空格
- 剑指offer面试题之替换空格
- 剑指offer-面试题4.替换空格
- [转载]广告联盟类型详解
- 数据输入/输出重定向
- Android自学小疑问、小知识点之 监听事件通过接口方式 多次实现监听器
- Android 自定义View (二) 进阶
- Symbol 'ANDROID_LOG_DEBUG' could not be resolved
- 剑指Offer面试题2:替换空格
- iTunes Connect 上传APP报错: Communication error. please use diagnostic mode to check connectivity.
- Java实现链式存储的线性表
- struts初探
- C语言模糊基础概念之强制类型转换
- 用strtok函数拆分字符串
- Linux内核的学习总结(一)
- ORA-19706: 无效的 SCN
- Bitmap的mutable属性引发的血案