首页 > 其他 > 详细

Hdu oj 1686 Oulipo

时间:2015-08-07 13:20:48      阅读:135      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<string.h>
#define N 10010
char str1[N],str2[N*100];
int cent,i,j;
int len1,len2;
int p[N];
void getp()
{
	i=0,j=-1;
	p[i]=j;
	while(i<len1)
	{
	   if(j==-1||str1[i]==str1[j])
       {
    	  i++,j++;
    	  p[i]=j;
       }
	   else
	   j=p[j];	
    }
}
void kmp()
{
	getp();
	i=0,j=0;
	while(i<len2)
	{
	   if(j==-1||str2[i]==str1[j])
       {
    	  i++,j++;
    	  if(j==len1)
    	  cent++;
       }
	   else
	   j=p[j];
    }
}
int main()
{
    int t;
	scanf("%d",&t);
	while(t--)
	{
		cent=0;
		scanf("%s%s",str1,str2);
		len1=strlen(str1);
		len2=strlen(str2);
		kmp();
		printf("%d\n",cent);
	}	
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Hdu oj 1686 Oulipo

原文:http://blog.csdn.net/zm_11/article/details/47337247

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