Combine Two Grids of Asterisks

The program must accept a grid of size N*N containing asterisks and exactly one hash symbol as the input. The hash symbol indicates the bottom-right corner of another N*N grid of asterisks. The program must print the combined grid of asterisks as shown in the Example Input/Output section. The empty spaces must be printed as hyphens.

Boundary Condition(s):
2 <= N <= 50

Input Format:
The first line contains N.
The next N lines, each contains N characters separated by a space.

Output Format:
The lines contain the combined grid of asterisks separated by a space.

Example Input/Output 1:
Input:
4
* * * *
* * * *
* # * *
* * * *

Output:
* * * * – –
* * * * * *
* * * * * *
* * * * * *
– – * * * *

Explanation:
Here N=4, so the size of grid is 4*4.
The combined 4*4 grids of asterisks is given below.
* * * * – –
* * * * * *
* * * * * *
* * * * * *
– – * * * *

Example Input/Output 2:
Input:
3
* # *
* * *
* * *

Output:
* * * –
* * * –
* * * *
– * * *
– * * *

Example Input/Output 3:
Input:
6
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * # *
* * * * * *

Output:
* * * * * * –
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
– * * * * * *

n=int(input())
l=[]
for i in range(n):
    l.append([val for val in input().split()])
for i in range(n):
    for j in range(n):
        if l[i][j]=='#':
            left=n-(j+1)
            top=n-(i+1)
            m=i
            x=j
for i in range(n+top):
    for j in range(n+left):
        if(i<top and j>=n):
                print('-',end=" ")
        elif(i>=n and j<left):
                print('-',end=" ")
        else:
            print('*',end=" ")

    print()
Previous Article

Minimum Size Pendrive - N Videos

Next Article

Area of Equilateral Triangle

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *