您的位置:首页 > 其它

计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;
}
运行结果:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: