Cut the flower cloth

Source: Internet
Author: User

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

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.