文章
17
粉丝
177
获赞
2
访问
118.3k
#include<stdio.h>
#include<string.h>
int main(){
char s[100], a[100], b[100];
while(gets(s) && gets(a) && gets(b)){
int start_pos = 0;
int end_pos = 0;
while(end_pos < strlen(s)){
while(s[end_pos] != ' ' && end_pos < strlen(s)) end_pos++; //找空格
char temp[100];
strncpy(temp, s + start_pos, end_pos - start_pos); //字符串赋值给temp
temp[end_pos - start_pos] = '\0'; //必须加这一句否则输出会有问题
if(!strcmp(temp, a)) printf("%s ", b);//与模板比较相同输出替换字符串,否则输出源字符串temp
else printf("%s ", temp);
start_pos = end_pos + 1;//更改位置进行下一次循环
end_pos = start_pos;
}
printf("\n");
}
}
登录后发布评论
暂无评论,来抢沙发