Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.
1
Expert's answer
2021-08-12T07:46:39-0400
m, n = map(int, input().split())
matrix = [[int(x) for x in input().split()] for _ in range(m)]
lmatrix = sorted(sum(matrix, []))
for i in range(m):
print(*lmatrix[i * n: i * n + n], end=' ')
print()
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment