04 替换空格
2016-05-19 22:00
351 查看
#include <stdio.h> void replaceblank(char str[], int len) { if (str == NULL || len<1) { return; } int reallong=0, blanks=0,i=0; while (str[i]!='\0') { if (str[i]==' ') { blanks++; } reallong++; i++; } int p1 = reallong, p2 = reallong + 2 * blanks; if (p2>len) { return; } while (p1!=p2) { if (str[p1]==' ') { str[p2--] = '0'; str[p2--] = '2'; str[p2--] = '%'; } else { str[p2--] = str[p1]; } p1--; } } void main() { char a[100]; gets(a); replaceblank(a, 100); printf("%s", a); }
测试结果:
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/sad.gif)
相关文章推荐
- 水题只会让自己更水,告别水题
- Apache访问控制
- poj 2653 线段与线段相交
- Extjs MVC架构 (官方文档翻译)【带源码】
- 创建tornado应用输出hello world
- Eclipse添加注释模板
- TensorFlow Machine Learning with Financial Data on Google Cloud Platform
- Python map reduce
- MySQL入门--创建数据库、显示警告信息、显示数据库、显示数据库创建信息、指定字符编码集
- LeetCode-237.Delete Node in a Linked List
- 如何去掉导航器下面的黑线
- Linux面试题(1)
- 闽江学院软件学院2015级学生职业人物访谈
- 九度OJ 1348-数组中的逆序对【逆序对模板】
- 前端性能优化小知识点(javascript)
- JavaScript Array和string的转换
- c语言学习笔记11
- JAVA-008类和对象
- 【数塔】1002 数塔取数问题【51nod】
- Apache配置防盗链