import random
def magic(n):
matrix = []
def sort(array):
i = 0
def check(array):
for j in range(len(array) - 2):
if array[j] > array[j + 1]:
return False
return True
while True:
if array[i] > array[i + 1]:
max = array[i]
array[i] = array[i + 1]
array[i + 1] = max
i += 1
if i > len(array) - 2:
if check(array):
break
return array
def writeMatrix(matrix):
for arr in matrix:
print(arr)
for row in range(n):
matrix.append([])
for column in range(n):
matrix[row].append(random.randint(-50, 50))
print("Non sorted")
writeMatrix(matrix)
print()
arr = sort(arr)
print("Sorted rows")
writeMatrix(matrix) # sorted rows
column = []
column.append(arr[0])
column = sort(column)
for j in range(len(column) - 1):
matrix[j][0] = column[j]
print("Full sorted")
writeMatrix(matrix) # sorted rows and columns
def main():
n = int(input())
magic(n)
main()
import random
def magic(n):
matrix = []
def sort(array):
i = 0
def check(array):
for j in range(len(array) - 2):
if array[j] > array[j + 1]:
return False
return True
while True:
if array[i] > array[i + 1]:
max = array[i]
array[i] = array[i + 1]
array[i + 1] = max
i += 1
if i > len(array) - 2:
i = 0
if check(array):
break
return array
def writeMatrix(matrix):
for arr in matrix:
print(arr)
for row in range(n):
matrix.append([])
for column in range(n):
matrix[row].append(random.randint(-50, 50))
print("Non sorted")
writeMatrix(matrix)
print()
print()
for arr in matrix:
arr = sort(arr)
print("Sorted rows")
writeMatrix(matrix) # sorted rows
column = []
for arr in matrix:
column.append(arr[0])
column = sort(column)
for j in range(len(column) - 1):
matrix[j][0] = column[j]
print()
print()
print("Full sorted")
writeMatrix(matrix) # sorted rows and columns
def main():
n = int(input())
magic(n)
main()
import random
def magic(n):
matrix = []
def sort(array):
i = 0
def check(array):
for j in range(len(array) - 2):
if array[j] > array[j + 1]:
return False
return True
while True:
if array[i] > array[i + 1]:
max = array[i]
array[i] = array[i + 1]
array[i + 1] = max
i += 1
if i > len(array) - 2:
i = 0
if check(array):
break
return array
def writeMatrix(matrix):
for arr in matrix:
print(arr)
for row in range(n):
matrix.append([])
for column in range(n):
matrix[row].append(random.randint(-50, 50))
print("Non sorted")
writeMatrix(matrix)
print()
print()
for arr in matrix:
arr = sort(arr)
print("Sorted rows")
writeMatrix(matrix) # sorted rows
column = []
for arr in matrix:
column.append(arr[0])
column = sort(column)
for j in range(len(column) - 1):
matrix[j][0] = column[j]
print()
print()
print("Full sorted")
writeMatrix(matrix) # sorted rows and columns
def main():
n = int(input())
magic(n)
main()