KMP还不会,只能暴力了
#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; }
KMP还不会,只能暴力了