#K72087. Unique Password Generator
Unique Password Generator
Unique Password Generator
You are given a password template of length \(n\) consisting of lowercase letters and the character '?' representing an unknown character. For each position where the template has a '?', you are provided with a string of possible characters that can fill that position. Your task is to calculate the total number of unique passwords that can be generated by replacing each '?' with one of the available characters for that position.
The answer is given by the formula:
[ \text{result} = \prod_{i=1}^{n} \begin{cases} \text{length}(possible_chars[i]) & \text{if } template[i]=='?' \ 1 & \text{otherwise} \end{cases} ]
For example, if \(n = 3\), template is "a?c" and the available characters for the unknown position (i.e. for index 1) is "bce", then the total number of unique passwords is \(3\).
inputFormat
The input is read from stdin
and has the following format:
- The first line contains an integer \(n\), the length of the password.
- The second line contains a string representing the password template.
- The next \(n\) lines each contain a string. The \(i\)-th of these lines gives the possible characters that can fill the \(i\)-th position if the template character is a '?'. For positions where the template already specifies a fixed character, the corresponding line will be an empty string.
outputFormat
Output a single integer to stdout
: the total number of unique passwords that can be generated.
3
a?c
bce
3
</p>