首页 > 代码库 > ZOJ 3957 Knuth-Morris-Pratt Algorithm

ZOJ 3957 Knuth-Morris-Pratt Algorithm

暴力。

#include<bits/stdc++.h>using namespace std;char s[2000];int main(){    int T; scanf("%d",&T);    while(T--)    {        scanf("%s",s);        int ans=0;        int len=strlen(s);        for(int i=0;i<len-2;i++)        {            if(s[i]==d&&s[i+1]==o&&s[i+2]==g) ans++;            if(s[i]==c&&s[i+1]==a&&s[i+2]==t) ans++;        }        printf("%d\n",ans);    }    return 0;}

 

ZOJ 3957 Knuth-Morris-Pratt Algorithm