字符串替换

字符串替换

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
描述
编写一个程序实现将字符串中的所有"you"替换成"we"
输入
输入包含多行数据 

每行数据是一个字符串,长度不超过1000 
数据以EOF结束
输出
对于输入的每一行,输出替换后的字符串
样例输入
you are what you do
样例输出
we are what we do

题目转自南阳理工学院:http://acm.nyist.edu.cn/JudgeOnline/problemset.php


个人代码(以下原创)

#include <stdio.h>
#include <string.h>

int main()
{
	char a[1100] = {0};
	while (gets(a))
	{
		int x = strlen(a);
		char b[1100] = {0};
		int j = 0;
		for (int i = 0; i < x; i++)
		{
			if (a[i] == 'y' && a[i+1] == 'o' && a[i+2] == 'u')
			{
				b[j] = 'w';
				b[j+1] = 'e';
				i = i+2;
				j += 2;
			}
			else
			{
				b[j] = a[i];
				j += 1;
			}
		}
		printf("%s\n", b);
		for (int i = 0; i < x; i++)
		{
			a[i] = 0;
		}
	}
	return 0;
}


posted @ 2018-02-11 21:58  focus5679  阅读(128)  评论(0编辑  收藏  举报