Cut the flower clothTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 9295 Accepted Submission (s): 6047
problem Descriptiona 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?
InputThe input contains 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.
Outputoutput 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 a3aaaaaa aa#
Sample Output
Genevaproblem-solving ideas: string pattern matching http://blog.csdn.net/zchlww/article/details/41725363Source code:#include <stdio.h> #include <string.h> #include <stdlib.h> #define SIZE 1010 char s[ Size], t[size]; int Next[size]; void GetNext ()//for pattern string T next[] value { int j,k; j=0;k=-1;next[0]=-1; while (j< Strlen (t)-1) { if (K==-1 | | t[j]==t[k])//k to 1 or compare words typeface etc { j++;k++;& nbsp Next[j]=k; } else k=next[k]; } }int kmpindex () { int i=0,j =0,count=0; GetNext (); while (I<strlen (s)) { if (strlen (t) ==j) count++; if (J==-1 | | s[i]==t[j]) { i++; & nbsp //I,J each add 1 J + +; } ELSE J=NEXT[J]; //i unchanged, J back } if (strlen (s) ==i && strlen (t) ==j) &N bsp; count++; return count; }int main () { int i, J; while (scanf ("%s%s", s,t)! = EOF && strcmp (S, "#")!=0) { printf ("%d\n", Kmpindex ()), &NBSP ; } System ("pause"); return 0; &NBSP;}
Cut the flower strips