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
Output
Boundary Conditions
Example Input/Output 1
Input
Output
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
Comments