0316 - Min Cols 2

From Bitnami MediaWiki
Revision as of 17:58, 4 April 2023 by Andor Giulia (talk | contribs)

Rezolvare

<syntaxhighlight lang="python" line> m, n = map(int, input().split()) a = [] for i in range(m):

   row = list(map(int, input().split()))
   a.append(row)
  1. determinarea valorii minime din matrice

min_val = 10000 for i in range(m):

   for j in range(n):
       if a[i][j] < min_val:
           min_val = a[i][j]
  1. înlocuirea elementelor de pe coloanele care conțin valoarea minimă cu valoarea minimă

for j in range(n):

   col_min = 10000
   for i in range(m):
       if a[i][j] < col_min:
           col_min = a[i][j]
   if col_min == min_val:
       for i in range(m):
           a[i][j] = min_val
  1. afișarea matricei modificate

for i in range(m):

   for j in range(n):
       print(a[i][j], end=' ')
   print()

</syntaxhighlight>