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

Description

編寫一個C程序?qū)崿F(xiàn)將字符串中的所有"you"替換成"we"

Input

輸入包含多行數(shù)據(jù)

每行數(shù)據(jù)是一個字符串,長度不超過1000
數(shù)據(jù)以EOF結(jié)束

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