#K73747. Word Pattern Matching

    ID: 34044 Type: Default 1000ms 256MiB

Word Pattern Matching

Word Pattern Matching

You are given a pattern string and a space-separated string s. Your task is to determine if s follows the same pattern specified by the pattern string.

In other words, there must be a one-to-one mapping between a letter in pattern and a non-empty word in s. For example, if we have:

\( pattern = \texttt{abba} \) and \( s = \texttt{dog cat cat dog} \)

the function should return True since the mapping is consistent (\( a \rightarrow \texttt{dog} \) and \( b \rightarrow \texttt{cat} \)). Conversely, if \( s \) were "dog cat cat fish", the mapping would break and you should return False.

Your solution should read input from stdin and output the result to stdout.

inputFormat

The input consists of two lines:

  • The first line contains the pattern string.
  • The second line contains the space-separated string s.

Both lines are non-empty.

outputFormat

Output a single line with either True or False (without quotes) depending on whether the string s follows the pattern.

## sample
abba
dog cat cat dog
True