#C1759. Word Pattern Matching
Word Pattern Matching
Word Pattern Matching
You are given a pattern string and a string s
consisting of words separated by spaces. The task is to determine if s
follows the same pattern as described by pattern
. In other words, there should be a bijection between a letter in pattern
and a word in s
.
More formally, let \( P = p_1p_2...p_n \) be the pattern and \( s = w_1 w_2 ... w_n \) be the word sequence. The string s
follows the pattern if for every \( i \) (\( 1 \le i \le n \)) the mapping \( p_i \rightarrow w_i \) is consistent and one-to-one.
inputFormat
The input consists of two lines from standard input:
- The first line contains the pattern string.
- The second line contains a sequence of words separated by spaces.
outputFormat
Print a single line to standard output containing true
if the string follows the pattern, or false
otherwise.
abba
dog cat cat dog
true