字符串替换

来源:互联网 发布:java动态创三维数组 编辑:程序博客网 时间:2024/05/22 13:48

字符串替换Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

SubmitStatus

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>#include <stdlib.h>int main(){    char str[1010];    int i;    int len;    while(gets(str))    {        len= strlen(str);        for(i=0;i<len;i++)        {            if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u')            {                printf("we");                i+=2;            }            else            {                printf("%c",str[i]);            }        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击