ACM POJ 3981 字符串替换(简单题)

字符串替换

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 5975Accepted: 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;
}
    原文作者:kuangbin
    原文地址: https://www.cnblogs.com/kuangbin/archive/2011/09/15/2178107.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞