Vertical Printing
You are given a string(S) with multiple words in it. Return all the words vertically in the same order in which they appear in S.
Complete with spaces when it is necessary while forming the words vertically. (Trailing spaces are not allowed).
Note: All characters in S are upper case.
Input
The first line contains a string S.
Output
Each line of the output contains a string formed vertically as mentioned above.
Explanation
Given S = CAT BAT VIN.
We are expected to print the words vertically such that considering the ith letter in each line of the output will form the ith word in the given input.
Printing the given words vertically
Joining all the first characters from the 3 lines of output gives CAT.
Joining all the second characters from the 3 lines of output gives BAT.
Joining all the third characters from the 3 lines of output gives VIN.
Sample Input 1
CAT BAT VIN
Sample Output 1
CBV
AAI
TTN
Sample Input 2
MAM BY DORM
Sample Output 2
MBD
AYO
M R
M
s = 'MAM BY DORM'
w = s.split(' ')
for i in range(len(max(w, key=len))):
for ww in w:
if i < len(ww):
print(ww[i], end = '')
else:
print(' ', end = '')
print('')
Comments
Leave a comment