您的位置:首页 > 博客中心 > 互联网 >

XDOJ_1140_KMP

时间:2022-04-30 20:39

http://acm.xidian.edu.cn/problem.php?id=1140

 

KMP效率真心低,cstring中的strstr快多了。

 

#include
#include
#include
#include
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int ans = 0;
        char a[50000],b[50000];
        while(n--)
        {
            scanf("%s",a);
            strcat(b,a);
            char *p = b,*o;
            while(o = strstr(p,"wanshen"))
            {
                p = o+7;
                ans++;
            }
            strcpy(b,p);
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

本类排行

今日推荐

热门手游