Monday, September 18, 2017

Three Strings

Given N string values, the program must print 3 string values as the output as described in the Example Input/Output section.

Input format:
The first line will contain N denoting the number of string values. Next N lines will contain the N string values.

Output format:
Three lines containing string values as described in the Example Input/Output section.
                                          
Example Input/Output 1:
Input:
3
JOHN
JOHNY
JANARDHAN
Output:
JJOJAN
OHHARD
NNYHAN

Example Input/Output 2:
Input:
4
JOHN
JOHNY
JANARDHAN
MIKESPENCER
Output:
JJOJANMIKE
OHHARDSPE
NNYHANNCER

Solution:
x,a,b,c=int(input())," "," "," "
s=[input().strip() for _ in range(x)]
for i in range(x):
    a+=s[i][0:i+1]
    b+=s[i][i+1:len(s[i])-i-1]
    c+=s[i][len(s[i])-i-1:]
print(a.strip(),'\n',b.strip(),'\n',c.strip())
Share: