poj 3981 字符串替换

字符串替换
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6311   Accepted: 2943

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 you[]="you";
char we[]="we";
char income[1001];
int i,j;
int l;
while(gets(income))
{
l=strlen(income);
for(i=0;i<l;i++)
{
if(income[i]=='y'&&income[i+1]=='o'&&income[i+2]=='u')
{
income[i]='w';
income[i+1]='e';
for(j=i+2;j<l;j++)
{
income[j]=income[j+1];
}
}
}
printf("%s\n",income);
}
}

posted @ 2011-11-23 11:22  w0w0  阅读(151)  评论(0)    收藏  举报