/*
Copyright(c)2016,烟台大学计算机学院
All rights reserved.
文件名称:tset.cpp
作者:尤文敏
完成日期:2016年12月13日
版本号:v1.0
题目描述 :
字符串的替换
问题及代码:
#include <stdio.h> #include <stdlib.h> int main() { char str[1000]; int i; while(gets(str)!=NULL) { i=0; for(i=0;str[i]!='\0';i++) if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') { printf("we"); i=i+2; } else { printf("%c",str[i]); } printf("\n"); } return 0; }
运行结果:
知识点总结:
在字符串的替换中,首先就是要找到被替换的位置,其次就是替换,而不被替换的地方仍按照原来输出。
学习心得:
发现问题的本质,解决问题!加油加油加油!!!