POJ-3461 Oulipo (KMP, number of pattern strings appearing in the main string)

Source: Internet
Author: User

Test instructions: give you two strings p and s to find out how many times p appears in S.

I want to get p directly to the front of S, then the next array to strlen (p) Take the remainder ==0 can, after WA. Finally found that a aassaas when there is a bug, only to think of P and s in the middle of an impossible character ' $ ' on it, the ring is a.

#include <bits/stdc++.h>using namespacestd;Const intinf=0x3f3f3f3f; typedefLong Longll;#definePI (a) printf ("%d\n", a)#defineSI (n) scanf ("%d",& (n))#defineSII (n,m) scanf ("%d%d",& (N),& (M))#defineCLE (A,val) memset (A, (Val), sizeof (a))#defineRep (i,b) for (int i=0;i< (b); i++)#defineREP (I,A,B) for (int i= (a); i<= (b); i++)#defineREReP (I,A,B) for (int i= (a); i>= (b); i--)Const Doubleeps= 1e-9 ;/*/////////////////////////c o d i n g S p a C e/////////////////////////*/Const intmaxn=10000+1000000+9 ;voidKmp_pre (intX[],intMintnext[]) {    inti,j; J=next[0]=-1; I=0;  while(i<m) { while(-1!=J&AMP;&AMP;X[I]!=X[J]) j=Next[j]; next[++i]=++J; }}intNEXT[MAXN],INP[MAXN];intn,m;Charstr1[10000+5],str2[1000000+5];intMain () {into;    SI (o);  while(o--) {scanf ("%s", STR1); scanf ("%s", STR2); N=strlen (str1), m=strlen (STR2); Str1[n]='$'; N++;  for(intI=0; i<n;i++) Inp[i]=Str1[i];  for(inti=n;i<n+m;i++) Inp[i]=str2[i-N]; Kmp_pre (Inp,n+m,next); intans=0; Rep (i,1, n+m)if(next[i]% (n1)==0&&next[i]!=0) ans++;    PI (ANS); }    return 0;}

POJ-3461 Oulipo (KMP, number of pattern strings appearing in the main string)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.