字符串转换201307291519.txt

字符串替换
Time Limit: 1000MS  Memory Limit: 65536K
Total Submissions: 8492  Accepted: 4009

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>
int main()
{
 char a[1000];
 int i,j,n;
 while(gets(a))
 {
 n=strlen(a);
 for(i=0;i<n;i++)
 if(a[i]=='y'&&a[i+1]=='o'&&a[i+2]=='u')
 { a[i]='w';
  a[i+1]='e';
  for(j=i+2;j<n;j++)
  a[j]=a[j+1];
}
  printf("%s ",a);
 }
 return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
 char str[1010];
 while(gets(str))
 {
  int i;
  for(i=0;i<strlen(str);i++)
  {
   if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u')
   {
    printf("we");
    i+=2;
   }
   else
   printf("%c",str[i]);
  }
  printf(" ");
 }
 return 0;
}

原文地址:https://www.cnblogs.com/xiaziteng/p/ZIFUCHUANZHUANHUAN.html