A piece of flower cloth, there are some patterns, there is a directly available small bar, there are some patterns. For a given strip of flowers and strips, calculate how many pieces of strips can be cut from the flower cloth as much as possible.
Input inputs contain some data, respectively, is a pair of flowers and small strips, the cloth is shown with visible ASCII characters, the number of visible ASCII characters, the pattern of the cloth is also how many kinds of patterns. The strips and strips are not more than 1000 characters in length. If you meet the # character, you are no longer working.
Output outputs can be cut from the pattern cloth up to the number of small strips, if not a piece, then honestly output 0, each result should be wrapped.
Sample Input
ABCDE a3
aaaaaa AA
#
Sample Output
0
3
Test instructions: ""
Idea: template KMP algorithm ...
#include <cstdio>
#include <cstring>
#include <algorithm>
const int n=1000005;
using namespace std;
int next[1005];
Char s[1005],t[1005];
int KMP (char* s,int l1,char* t,int L2)
{
int i=0,j=0,k=0;
while (I<L1)
{
if (j==-1| | S[I]==T[J])
{
++i;
++j;
if (J==L2)
{
i+=l2-1;
k++;
}
}
else
j=next[j];
}
return k;
}
void Getnext (char *t,int L2)
{
int i=0,j;
Next[i]=-1;j=next[i];
while (I<L2)
{
if (j==-1| | T[I]==T[J])
next[++i]=++j;
else
j=next[j];
}
}
int main ()
{
while (~scanf ("%s", s))
{
if (s[0]== ' # ') break;
scanf ("%s", t);
int L1=strlen (s), L2=strlen (t);
Getnext (T,L2);
printf ("%d\n", KMP (S,L1,T,L2));
}
return 0;
}