POJ 3981 字符串替换
字符串替换
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8278 | Accepted: 3907 |
Description
编写一个C程序实现将字符串中的所有"you"替换成"we"
Input
输入包含多行数据
每行数据是一个字符串,长度不超过1000
数据以EOF结束
每行数据是一个字符串,长度不超过1000
数据以EOF结束
Output
对于输入的每一行,输出替换后的字符串
Sample Input
you are what you do
Sample Output
we are what we do
如此大水居然CE一次,好心疼T^T
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 4 using namespace std; 5 6 char s[1010]; 7 8 int main() 9 { 10 while(gets(s)) 11 { 12 for(int i=0,t=strlen(s)-2;i<t;i++) 13 if(s[i]=='y'&&s[i+1]=='o'&&s[i+2]=='u') 14 { 15 s[i]='w'; 16 s[i+1]='e'; 17 for(int j=i+2;j<strlen(s);j++) 18 s[j]=s[j+1]; 19 --t; 20 } 21 puts(s); 22 } 23 24 return 0; 25 }