计161_Problem : 字符串替换(串)
2017-03-26 22:26
204 查看
/*Description 编写一个C程序实现将字符串中的所有"you"替换成"we" Input 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 Output 对于输入的每一行,输出替换后的字符串 Sample Input you are what you do Sample Output we are what we do HINT*/ #include <stdio.h> #include <stdlib.h> #include<string.h> int main() { char str[1000]; int i,j; while(gets(str)!=NULL) //gets返回的是指针,所以用NULL { for(i=0;i<strlen(str);i++) if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') { str[i]='w'; str[i+1]='e'; for(j=i+2;str[j]!='\0';j++) str[j]=str[j+1]; } puts(str); } return 0; }
运行结果:
相关文章推荐
- 第15周 oj Problem L: 字符串替换(串)
- 计161_Problem : 字符串操作一(串)
- 计161_Problem : 字符串操作二(串)
- JAVA正则表达式替换字符串问题
- SQL替换指定列字符串
- Python - 字符串模板的安全替换(safe_substitute) 具体解释
- 计161_Problem X: 转义字符的使用
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 替换文件中的字符串(C语言实现)
- linux shell字符串内置的常用操作(获取长度、查找、替换)
- Replace 字符串替换
- 字符串替换 java/c++
- 简单的字符串替换
- linux shell 字符串操作(长度,查找,替换)详解
- 替换掉字符串中的空格
- mysql字符串替换
- 【剑指offer】字符串中空格的替换
- 用STL实现字符串字串替换
- C++实现字符串替换的两种方法
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)