Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
3 3
1 2 3
5 10 11
15 20 30
def main():
n, m = map(int, input('n, m : ').split())
l = list()
for i in range(n):
l.append(list(map(int, input().split())))
a = list()
for item in l:
for i in item:
a.append(i)
a.sort()
k = 0
for i in range(n):
for j in range(m):
l[i][j] = a[k]
k += 1
for i in l:
for j in i:
print(j, end=' ')
print()
if __name__ == '__main__':
main()
Comments
Leave a comment