#C4529. Maximum Number of Words Formed
Maximum Number of Words Formed
Maximum Number of Words Formed
Given two strings s
and t
, determine the maximum number of times you can form the word t
from the characters in s
. Each formation of t
uses the characters in s
according to their frequency, and the characters required for t
must appear in s
in at least the necessary count. Formally, the answer is computed as
$$ \text{result} = \min_{c \in t} \left\lfloor \frac{\text{count}_s(c)}{\text{count}_t(c)} \right\rfloor $$
where \(\text{count}_s(c)\) and \(\text{count}_t(c)\) denote the number of times character c appears in s
and t
respectively. If a character in t
is not present in s
, then the answer is 0.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains the string
s
. - The second line contains the string
t
.
outputFormat
Output a single integer to stdout — the maximum number of times t
can be formed using the characters from s
.
ababcb
ab
2