Four Strings Rectangle

 Coding Problem Keys 

 Four Strings Rectangle 

 Problem Statement 

Four strings out of which two have the same length L1 and the remaining two have the same length L2 are passed as the input to the program. The four strings must be printed in a L1*L2 rectangular matrix shape as shown in the example input/output.

L1>=L2 and a string with L1 must appear on the top of the rectangle. The string which is on the top with length L1 will always be the first string in the input. Other three strings can occur in a random order in the input. The sequence of the string can be identified by the fact that the last letter of a string will be the first letter of another string (and you can safely assume the last letter will not occur more than once).

 Input Format 

The first line contains the string which represents the top of the rectangular matrix.
The next three lines will contain the remaining the three string values which can represent the right, left and bottom side of the rectangle, but not necessarily in the same order.

 Output

The L1*L2 rectangular matrix with these four strings as it's sides as described in the Example Input/Output.

 Boundary Conditions 

3 <= L1, L2 <= 100
L1 >= L2

 Example Input/Output 1 

 Input 

MANAGE
SUM
TAURUS
EAT

 Output 

MANAGE
U****A
SURUAT

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

l=[input().strip() for i in range(4)]
l2=[l[0]]
l=l[1:]
for i in range(1,4):
    for j in l:
        if j[0]==l2[i-1][-1]:
            l2.append(j)
            l.remove(j)
print(l2[0])
a=len(l2[0])
b=len(l2[1])
ind=1
for i in range(b-2):
    print(l2[-1][-ind-1]+'*'*(a-2)+l2[1][ind])
    ind+=1
print(l2[-2][::-1])
#Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Unknown said…
It's worked thanks

Popular Posts

Top Scoring Batsman - TEST ODI 20-20

Largest Possible Number With Digits

Highly Profitable Months

Minimum Sum of Non-Negative Elements

String - Vowels Position Sum

Count Embedded Integers in String

Desktop Products