#C64. Word Formation Verification
Word Formation Verification
Word Formation Verification
You are given a target string s and a list of words. Your task is to determine whether the target string can be completely formed using the letters from the words in the list. Each word in the list can be used an unlimited number of times. The procedure is case-insensitive and all non‐alphabetic characters in the target string should be ignored.
Mathematically, if we let \( s \) be the target string and use \( \text{cnt}_s(c) \) to denote the frequency of a letter \( c \) in \( s \) (ignoring non-alphabetic characters), and let \( \text{cnt}_w(c) \) denote the total frequency of \( c \) in the concatenation of all words, then the target string can be formed if and only if for every alphabet letter \( c \), \[ \text{cnt}_s(c) \leq \text{cnt}_w(c)\] for all \( c \) in the English alphabet.
For example, consider \( s = \texttt{hellopython} \) and the words list \( [\texttt{hello},\ \texttt{world},\ \texttt{python},\ \texttt{java}] \). In this case, all required letters are available in sufficient quantity, so the answer is True
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the target string s (which may include non-alphabetic characters).
- The second line contains a space-separated list of words.
outputFormat
Output to standard output (stdout) a single line: True
if the target string can be formed using the letters in the words list, or False
otherwise.
hellopython
hello world python java
True