提交记录 #446
提交时间:2024-12-05 09:03:57
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:11:18: warning: variable ‘len_s’ set but not used [-Wunused-but-set-variable]
11 | int i, j, k, len_s, len_t, len_str, count = 0;
| ^~~~~
固定测试点#1:
固定测试点#2:
固定测试点#3:
额外测试点#2:
52【字符】字符替换*——用指针更方便
#include <stdio.h>
#include <string.h>
#define MAX_LEN 101
int main() {
char s[MAX_LEN];
char t[11];
char str[11];
char result[MAX_LEN];
int i, j, k, len_s, len_t, len_str, count = 0;
fgets(s, MAX_LEN, stdin);
fgets(t, 11, stdin);
fgets(str, 11, stdin);
s[strcspn(s, "\n")] = 0;
t[strcspn(t, "\n")] = 0;
str[strcspn(str, "\n")] = 0;
len_s = strlen(s);
len_t = strlen(t);
len_str = strlen(str);
result[0] = '\0';
i = 0;
j = 0;
while (s[i] != '\0') {
int match = 1;
for (k = 0; k < len_t; k++) {
if (s[i + k] == '\0' || s[i + k] != t[k]) {
match = 0;
break;
}
}
if (match) {
strcat(result, str);
j += len_str;
i += len_t;
count++;
} else {
result[j++] = s[i++];
result[j] = '\0';
}
}
printf("%s\n", result);
return 0;
}