字符串替换
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9289 | Accepted: 4442 |
Description
编写一个C程序实现将字符串中的所有"you"替换成"we"
Input
输入包含多行数据
每行数据是一个字符串,长度不超过1000
数据以EOF结束
每行数据是一个字符串,长度不超过1000
数据以EOF结束
Output
对于输入的每一行,输出替换后的字符串
Sample Input
you are what you do
Sample Output
we are what we do
<span style="font-size:18px;">#include <iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> using namespace std; int main() { char a[1001]; while(gets(a)!=NULL) { for(int i=0; a[i]!='\0'; i++) if(a[i]=='y'&&a[i+1]=='o'&&a[i+2]=='u') { a[i]='w'; a[i+1]='e'; a[i+2]=1;//将ude位置随便定义为一个字符 } for(int j=0;a[j]!='\0';j++) { if(a[j]==1) continue;//继续执行循环 printf("%c",a[j]); } printf("\n"); } }</span>