Code For Alls..!

get the code!!

Saturday, 29 July 2017

Word Slot

A Square Matrix of N Rows and N Columns is passed as the input and also a String S of Length L is passed as input. The matrix has an empty slot of length L denoted by + and remaining cells are denoted by #, with a space separating them.
Example of a slot of length 3 in the first row starting from column 2 and ending at column 4:
# + + + #
# # # # #
# # # # #
# # # # #
# # # # # 
Input Format:
First line contains N.
Next N lines contain the matrix cell values as described above.
The final line contains S
Output Format:
Matrix is printed with the empty cell slots denoted by + filled with the characters in string S.
Boundary Conditions:
1 <= N <= 100
1 <= Length of S <= 100

Example Input/Output 1:
Input:
5
# # + # #
# # + # #
# # + # #
# # + # #
# # + # #
India
Output:
# # I # #
# # n # #
# # d # #
# # i # #
# # a # #
Example Input/Output 2:
Input:
3
# + +
# # #
# # #
Hi
Output:
# H i 
# # # 
# # # 

Python:

n=int(input())
l=[]
for _ in range(n):
    l.append(input().strip().split())
s=input().strip()
k=0
for i in range(n):
    for j in range(n):
        if l[i][j]=='+':
            l[i][j]=s[k]
            k=k+1
for x in l:
    print(*x)

No comments:

Post a Comment