String Pattern - Inverted U

 Coding Problem Keys 

 String Pattern - Inverted U 

 Problem Statement 

Three strings S1, S2 and S3 are passed as the input. The program must print the pattern as shown in the Example Input/Output section. Out of these three strings, the two strings that are print along the left most column and the right most column will be of the same length. The string printed along the first row may or may not be equal in length to the other two strings but it's first character will be same as the first character of the string in the left most column and it's last character will be as same as the first character of the string in the right most column. The string values appearing on the top, left, right can appear in any order in the input.

 Boundary Condition(s) 

2 <= Length of strings <= 1000

 Input Format 

The first line contains the string value S1.
The second line contains the string value S2.
The third line contains the string value S3.

 Output Format 

The program must print the output as specified in Example Input/Output section.

 Example Input/Output 1 

 Input 

PANTHER
PATNA
ALLERGY

 Output 

PATNA
A***L
N***L
T***E
H***R
E***G
R***Y

 Example Input/Output 2 

 Input 

MANGOES
ECSTASY
MIRACLE

 Output 

MIRACLE
A*****C
N*****S
G*****T
O*****A
E*****S
S*****Y

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

a,b,c=input().strip(),input().strip(),input().strip()
if len(a)==len(b) and len(a)==len(c):
    if a[0]==c[0] and a[-1]==b[0]:
        b,c=c,b
    elif b[0]==a[0] and b[-1]==c[0]:
        a,b=b,a 
    elif b[0]==c[0] and b[-1]==a[0]:
        a,b,c=b,c,a 
    elif c[0]==b[0] and c[-1]==a[0]:
        a,c=c,a
    elif c[0]==a[0] and c[-1]==b[0]:
        a,b,c=c,a,b
elif len(a)==len(b):
    a,c=c,a 
elif len(a)==len(c):
    a,b=b,a 
if not (len(a)==len(b) and len(b)==len(c)):
    if a[0]!=b[0]:
        b,c=c,b
print(a)
for i,j in zip(b[1:],c[1:]):
    print(i+'*'*(len(a)-2)+j)

# Published By PKJCODERS

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

Comments

Popular Posts

Toggle Consonants Adjacent to Vowels

Top Scoring Batsman - TEST ODI 20-20

Java - Method Overriding - Area

Balloon Count Burst by Ath Kid

Microsoft

Mango Distribution