COCI '12 Contest 2 #2 Krizaljka

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

Do you like to solve crosswords? If you do, you probably know the traditional lead-in for beginners – small 3 by 3 crosswords, like the following:

Solve a crossword like this one! Not gonna happen? Fine, then at least put it together given six words that appear in it (three as horizontal and three as vertical).

Input Specification

Each of the six lines of input contains a word consisting of three uppercase English letters. The words are given in a lexicographically sorted order.

Output Specification

If it is impossible to put together a 3 by 3 crossword using the given six words, output 0. Otherwise, output the crossword in three lines.

If there is more than one possible solution, output the one that is first in lexicographic order, where, for sorting purposes, the crossword is viewed as a nine-letter word obtained by concatenating its rows.

Sample Input 1

ANA
ANA
DAR
DAR
RAD
RAD

Sample Output 1

DAR
ANA
RAD

Sample Input 2

EVO
HEP
HIR
IVA
PAD
ROD

Sample Output 2

HEP
IVA
ROD

Sample Input 3

AKO
CES
DOC
DON
ESI
KES

Sample Output 3

0

Comments

There are no comments at the moment.