首页 > 其他 > 详细

hdu 4150 Powerful Incantation

时间:2014-03-24 03:24:45      阅读:412      评论:0      收藏:0      [点我收藏+]

   计算字符串重复出现的次数。

可以用KMP来做。

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int i,j;
        char str[1000005],str1[10];
        scanf("%s %s",str,str1);
        int l1=strlen(str),l2=strlen(str1);
        int ans=0;
        for(i=0;i<l1;){
             int k=i;
            for(j=0;j<l2;){
                if(str[k]==str1[j]) {
                    j++;
                    k++;
                    continue;
                }
                else  break;
            }
            if(j==l2){
                i+=l2;
                ans++;
            }
            else i++;
        }
        printf("%d\n",ans);
    }
}


hdu 4150 Powerful Incantation,布布扣,bubuko.com

hdu 4150 Powerful Incantation

原文:http://blog.csdn.net/cnh294141800/article/details/21891559

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!