oj练习--字符串替换

来源:互联网 发布:家庭网络布线公司 编辑:程序博客网 时间:2024/05/17 19:21

Description

编写一个C程序实现将字符串中的所有"you"替换成"we"

Input

输入包含多行数据

每行数据是一个字符串,长度不超过1000

数据以EOF结束

Output

对于输入的每一行,输出替换后的字符串

Sample Input

you are what you do

Sample Output

we are what we do
 
 
 
#include<stdio.h>#include<string.h>int main(){    char a[1000];    int i;    while(gets(a))    {        for(i=0; a[i]!='\0'; i++)            if(a[i]=='y'&&a[i+1]=='o'&&a[i+2]=='u')            {                a[i]='w';                a[i+1]='e';                a[i+2]=-1;            }        for(i=0; a[i]!='\0'; i++)            if(a[i]!=-1)                printf("%c",a[i]);        printf("\n");    }    return 0;}

 
0 0