标签:接收 turn 替换 描述 越界 一个 行数据 null while
描述:
编写一个程序实现将字符串中的所有"you"替换成"we"
you are what you do
we are what we do
#include<stdio.h>
#include<string.h>
int main()
{
	char s[1005];
	int a,b,n,i;
	while(gets(s)!=NULL)//gets能接收含空格的字符串
	{
		a=strlen(s);
		for(i=0;i<a-2;i++)//a-2是说那个you在最后是扫到倒数第三位就行了,也避免下面的s[i+1],s[i+2]越界 
		{
			if(s[i]==‘y‘&&s[i+1]==‘o‘&&s[i+2]==‘u‘)
			{
				s[i]=‘w‘;
				s[i+1]=‘e‘;
				s[i+2]=‘#‘;//用#标注   输出是为# 略过就行 
			}
		}
		for(i=0;i<a;i++)
		{
			if(s[i]==‘#‘)continue;
			printf("%c",s[i]);
		}
		printf("\n");
	}
	return 0;
}
标签:接收 turn 替换 描述 越界 一个 行数据 null while
原文地址:http://www.cnblogs.com/hys1258414454/p/7226998.html