Miyu original, post Please note: Reprinted from __________ White House
Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2087
Description:Problem description
There are some patterns in a fabric, and some other small ornaments that can be used directly. For the given flower cloth and small ornaments, how many small ornaments can be cut out from the flower cloth as much as possible?
Input
The input contains some data, such as a pair of fabric and decoration. The fabric is represented by visible ASCII characters and the number of visible ASCII characters, how many patterns are there in the cloth pattern. The length of the pattern and ornament cannot exceed 1000 characters. If the # character is met, the job will not be started.
Output
The maximum number of small ornaments that can be cut out from the pattern cloth. If none of the ornaments exist, 0 will be output honestly, with a line break between each result.
Sample Input
ABCDE A3
Aaaaaa
#
Sample output
0
3
You can use strstr in C or string: Find () in C ++ to obtain
CCode:Miyu original, post Please note: Reprinted from __________ White House
# Include<Stdio. h>
# Include<String. H>
IntMain (Void)
{
IntLen, C;
Char *P;
CharA [1001], B [1001];
While (Scanf ( " % S " , A), [ 0 ] ! = ' # ' )
{
Scanf ( " % S " , B );
Len = Strlen (B );
For (C = 0 , P = A; P = Strstr (p, B); c ++ , P + = Len );
Printf ( " % D \ n " , C );
}
Return 0;
}
C ++ code:Miyu original, post Please note: Reprinted from __________ White House
# Include < Iostream >
# Include < String >
Using Namespace STD;
Int Main ()
{
String Word, STR;
While (CIN > Word, word ! = " # " )
{
CIN > STR;
Int Ncount = 0 ;
Int Len = Str. Size ();
Int Pos;
While (Pos = Word. Find (STR )) ! = String : NPOs)
{
Ncount ++ ;
Word = Word. substr (Pos + Len );
}
Cout < Ncount < Endl;
}
Return 0 ;
}