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

Description

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

Input

输入包含多行数据

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

Output

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

Sample Input

you are what you do

Sample Output

we are what we do

Source

 

 

#include<stdio.h>
#include
<string.h>
#include
<iostream>
using namespace std;
char str[1010];
int main()
{
int i;
int len;
while(cin.getline(str,1010))
{
len
=strlen(str);
for(i=0;i<len;i++)
{
if(i+2<len&&str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u')
{
printf(
"we");
i
+=2;
continue;
}
printf(
"%c",str[i]);
}
printf(
"\n");
}
return 0;
}

文章来源:http://www.cnblogs.com/kuangbin/archive/2011/09/15/2178107.html