Given a square matrix of order n*n, we need to print elements of the matrix in Z form.
Square matrix means “A matrix having same or equal number of rows and columns”.
INPUT:
1 0 1 0
0 1 0 1
1 0 1 0
0 1 1 1
OUTPUT:
1 0 1 0
0
0
0 1 1 1
def Zmatrx(Mx,r,c): for i in range(c-1): print(Mx[0][i],end=" ") for j in range(r-1): for k in range(c): if(j+k == c-1): print(Mx[j][k],end=" ") break print() #--> It is important print(end=" "*(k-1)) for k in range(0,c): print(Mx[r-1][k],end=" ") #Driver ''' Matrx=[[4, 5, 6, 8], [1, 2, 3, 1], [7, 8, 9, 4], [1, 8, 7, 5]] ''' #taking input manually Matrx=[] M=int(input("Row= ")) N=int(input("Column= ")) while True: arr=list(map(str,input().split(" "))) if arr != ['']: Matrx.append(list(map(int,arr))) else: break Zmatrx(Matrx,M,N) # WRITTEN BY legacyboy
INPUT_1:
Row= 4
Column= 4
1 0 1 0
0 1 0 1
1 0 1 0
0 1 1 1
OUTPUT:
1 0 1 0
0
0
0 1 1 1
INPUT_2:
Row= 4
Column= 4
4 5 6 8
1 2 3 1
7 8 9 4
1 8 7 5
OUTPUT:
4 5 6 8
3
8
1 8 7 5
ILLUSTRATION:
Morae Q!
- Find the length of the array’s longest increasing sub-sequence.
- Arrange numbers in a circle so that any two neighbouring numbers differ by 1.
- Find partial names and count the total numbers.
- Find the minimized sum of non-deleted elements of the array after the end of the game.
- Find the maximum number of good sleeping times optimally.
- Sort the elements of the array in the order in which they are required.
- Find the minimum number of flats, monkey needs to visit to catch ninjas.
- Convert the square matrix to matrix in Z form.
- Shift the K elements of each row to right of the matrix.
- Find maximum possible number of students in a balanced team with skills.
- Find the Maximum number of pairs of points you can match with each other.
- Calculate the number of non-empty good subarrays of given array.
- Transform the binary string A into the string B using finite operations.
- Find the number of potion must the character take to jump the hurdles.
- Count the total number of vowels and consonants.
- Return all elements of the matrix in spiral order.
- Return all palindromic paths of the matrix.
- Write the code to change the display in reverse order using pointer.
- Find the number of days the expedition can last.
- Find the minimum size of the sub-segment to make the array pairwise distinct.