#P7765. Crossword Intersection

    ID: 20952 Type: Default 1000ms 256MiB

Crossword Intersection

Crossword Intersection

Given two words A and B, your task is to place A horizontally and B vertically on a grid such that they intersect at a common letter. The intersection letter must be the first occurrence of that letter in both words. Formally, let A and B be two strings. Find the smallest index i (0-indexed) in A for which the character A[i] appears in B. Let j be the index of the first occurrence of A[i] in B. Then, place A in the j-th row (i.e. row j) and B in the i-th column (i.e. column i) of a grid. Fill every cell that is not part of A or B with a dot ('.').

For example, if A = "ABBA" and B = "CCBB", the first common letter is 'B'. The letter 'B' first appears in A at index 1 and in B at index 2. Thus, A is placed on row 2 and B is placed in column 1, resulting in the following grid:

.C..
.C..
ABBA
.B..

Make sure to use LaTeX formatting for any formulas, for example: $$ i \text{ and } j \text{ denote the indices in A and B respectively.} $$

inputFormat

The input consists of two lines. The first line contains the string A and the second line contains the string B. Both strings consist of uppercase letters only and it is guaranteed that there is at least one common letter between A and B.

outputFormat

Output the final grid. The grid should have as many rows as the length of B and as many columns as the length of A. The row where A is placed should print the string A entirely, while the other rows should have a single letter from B in the i-th column, where i is the position (0-indexed) in A at which the common letter appears, and a dot ('.') in every other position.

sample

ABBA
CCBB
.C..

.C.. ABBA .B..

</p>