#include <stdio.h>
#include <string.h>
int main(){
char str[201][101] = {{0}};
char input[201] = {0};
char a[201] = {0};
char b[201] = {0};
fgets(input, sizeof(input), stdin);
scanf("%s", a);
scanf("%s", b);
char *token = strtok(input, " ");
strcpy(str[0], token);
int i = 1;
while(token != NULL){
token = strtok(NULL, " ");
if(token != NULL){
strcpy(str[i], token);
i++;
}
}
for(int j=0; j<i; j++){
if(strcmp(str[j], a) == 0){
strcpy(str[j], b);
}
if(j != i-1)
printf("%s ", str[j]);
else
printf("%s", str[j]);
}
}
用c语言写的,就是不能全部AC,到底那里有问题啊?
代码里注释掉的那两行用gets更惨,只能通过一个测试用例,换成scanf就能多通过三个,但是还是有俩通过不了,吓得我都不敢用gets了。fgets是希望能接受到一个含空格的字符串。求大佬指点一下哪里有问题,我自己测试都没问题。