#C1759. Word Pattern Matching

    ID: 44999 Type: Default 1000ms 256MiB

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:

  1. The first line contains the pattern string.
  2. 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.

## sample
abba
dog cat cat dog
true