1 条题解

  • 0
    @ 2023-10-29 17:04:44

    #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

信息

难度
2
分类
(无)
标签
递交数
688
已通过
120
通过率
17%
被复制
6
上传者