poj3981字符串替换 水的以至于浪费时间的水题
字符串替换编写一个C程序实现将字符串中的所有"you"替换成"we"
输入包含多行数据
每行数据是一个字符串,长度不超过1000
数据以EOF结束
对于输入的每一行,输出替换后的字符串
#include<stdio.h>#include<string.h>int main(){int i,j;char s[1200];while(gets(s)){int d=strlen(s);for(i=0;i<d;i++){if(s[i]=='y'&&i+2<d&&s[i+1]=='o'&&s[i+2]=='u'){if(i==0&&(s[i+3]=='\0'||s[i+3]==' ')) {s[0]='w';s[1]='e';s[2]='+';}elseif(i==d-3&&s[d-4]==' ') {s[i]='w';s[i+1]='e';s[i+2]='+';}else{if(s[i-1]==' '&&s[i+3]==' ') {s[i]='w';s[i+1]='e';s[i+2]='+';}}}}for(i=0;i<d;i++)if(s[i]!='+') printf("%c",s[i]); printf("\n");}return 0;}