Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
M=int(input(""))
N=int(input(""))
nums= []
for i in range(0,M):
val_string=input("")
vals=val_string.split()
for val in vals:
nums.append(int(val))
nums.sort()
nums2d=[]
nums2d = [nums[r*N:(r+1)*N] for r in range(0,M)]
print()
for row in nums2d:
for e in row:
print(e, end=' ')
print()
Comments
Leave a comment