1 条题解
-
1
202502cj14周子祥 (周子祥) LV 8 @ 2025-06-08 16:37:21
#include <stdio.h>
#include <string.h>int main() {
char s[100001], t[101];
fgets(s, sizeof(s), stdin);
s[strcspn(s, "\r\n")] = '\0'; // 去掉换行符
fgets(t, sizeof(t), stdin);
t[strcspn(t, "\r\n")] = '\0'; // 去掉换行符int n = strlen(s);
int m = strlen(t);
int cnt = 0;for (int i = 0; i <= n - m; i++) {
int j;
for (j = 0; j < m; j++) {
if (s[i+j] != t[j]) {
break;
}
}
if (j == m) {
cnt++;
i += m - 1; // 匹配成功后,跳过已匹配的部分
}
}printf("%d\n", cnt);
return 0;
}
- 1
信息
- ID
- 1087
- 难度
- 3
- 分类
- (无)
- 标签
- 递交数
- 35
- 已通过
- 20
- 通过率
- 57%
- 上传者