C语言,b,c用gets不过,用scanf过了(附上全AC代码)
查看原帖
C语言,b,c用gets不过,用scanf过了(附上全AC代码)
740259
LuoLeGeGuGu楼主2022/8/3 16:45
    #include <stdio.h>
    #include<string.h>
    #include<math.h>
 int main(){
 	char a[205],b[105],c[105];//定义abc 
 	gets(a);//有空格 我用gets 
     scanf("%s %s",&b,&c);//疑惑的地方,用gets不行 
 	int alen=strlen(a),blen=strlen(b),cnt=0,temp=0;
 	for(int i=0;i<alen;i++){
 		for(int j=0;j<blen;j++){
 			if(a[i+j]==b[j]){//比较是否为需要替换的单词 
 				cnt++;
 				if(cnt==blen){
 					printf("%s",c);
 					temp=blen;//替换完成,a[i]输出跳过原单词长度 
				 }
		 }
		 }
		  cnt=0;
		 if(temp>0){
		 	temp--; 
		 	continue;//跳过 
		 }
		 printf("%c",a[i]);//按原来的输出,有替换就因为continue跳过 
	 }
 }

换成gets只能过第四个点。~感觉在编译器测试几个用例都没错呀~

2022/8/3 16:45
加载中...