3169. 字符串出现次数

Fifnmar
#include <cstdio>
int count(char s[], char t[]) {
    int cnt = 0;
    for (char *it = s; *it != '\0'; ++it)
        if (*it == *t) {
            char *i = it, *j = t;
            while (*i != '\0' && *j != '\0' && *i == *j)
                ++i, ++j;
            if (*j == '\0') {
                ++cnt;
                it = i - 1;
            }
        }
    return cnt;
}

int main() {
    char s[81], t[81];
    scanf("%s%s", s, t);
    printf("%d\n", count(s, t));
    return 0;
}
mansoup

KMP还不会,只能暴力了

你当前正在回复 博客/题目
存在问题!