您的位置:首页 > 其它

hdu-3981-字符串替换

2016-05-03 22:48 204 查看
Description

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

Input

输入包含多行数据

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

数据以EOF结束

Output

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

Sample Input

you are what you do

Sample Output

we are what we do

中文题目,直接模拟过去

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char s[10000];
while(gets(s))
{
int i,j;
int len=strlen(s);
for(i=0;i<len;i++)
{
if(s[i]=='y'&&s[i+1]=='o'&&s[i+2]=='u')
{
s[i]='w';
s[i+1]='e';
for(j=i+2;j<len;j++)
{
s[j]=s[j+1];
}
len--;
}
}
printf("%s\n",s);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: