#P7765. [COCI 2011/2012 #5] KRIŽALJKA

[COCI 2011/2012 #5] KRIŽALJKA

Description

There are two words AA and BB. Place AA horizontally and BB vertically. The overlapping part of the two words must be the same letter, and this letter must be the first occurrence in both AA and BB.

For example, when A="ABBA",B="CCBB", the output is as follows:

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

Input Format

One line containing two strings made up of uppercase letters, representing AA and BB.

Output Format

Output a matrix representing the placement result.

Cells without a character are represented by ..

BANANA PIDZAMA
.P....
.I....
.D....
.Z.... 
BANANA
.M....
.A....
MAMA TATA
.T..
MAMA
.T..
.A..
REPUBLIKA HRVATSKA
H........
REPUBLIKA
V........
A........
T........
S........
K........
A........

Hint

The testdata guarantees that a solution exists.

The strings consist of uppercase letters.

Translated from COCI 2011/2012 #5 T1

Translated by ChatGPT 5