POJ3981 字符串替换

来源:互联网 发布:黑魂三捏脸数据男 编辑:程序博客网 时间:2024/06/06 01:47
字符串替换
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9285 Accepted: 4438

Description

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

Input

输入包含多行数据 

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

Output

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

Sample Input

you are what you do

Sample Output

we are what we do

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <algorithm>using namespace std;int main(){    char str1[1001],str2[1001];    int i;    while(gets(str1)!=NULL)    {        int len=strlen(str1);        for(i=0;i<len;i++)        {            if(str1[i]=='y'&&str1[i+1]=='o'&&str1[i+2]=='u')            {                str1[i]='w';                str1[i+1]='e';                str1[i+2]=1;            }        }        for(i=0;i<len;i++)        {            if(str1[i]!=1)            printf("%c",str1[i]);        }        printf("\n");    }}


0 0