0779 - Vecini Pari

From Bitnami MediaWiki
Revision as of 19:26, 3 April 2023 by MiclausIoana (talk | contribs) (Pagină nouă: == Rezolvare == <syntaxhighlight lang="python" line="1"> n, m = map(int, input().split()) matrix = [] for i in range(n): row = list(map(int, input().split())) matrix.append(row) count = 0 for i in range(n): for j in range(m): if i > 0 and matrix[i-1][j] % 2 == 1: # verificăm vecinul de sus continue if i < n-1 and matrix[i+1][j] % 2 == 1: # verificăm vecinul de jos continue if j > 0 and matrix[i][j-1] % 2 == 1:...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rezolvare

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

   row = list(map(int, input().split()))
   matrix.append(row)

count = 0 for i in range(n):

   for j in range(m):
       if i > 0 and matrix[i-1][j] % 2 == 1:  # verificăm vecinul de sus
           continue
       if i < n-1 and matrix[i+1][j] % 2 == 1:  # verificăm vecinul de jos
           continue
       if j > 0 and matrix[i][j-1] % 2 == 1:  # verificăm vecinul din stânga
           continue
       if j < m-1 and matrix[i][j+1] % 2 == 1:  # verificăm vecinul din dreapta
           continue
       count += 1

print(count) </syntaxhighlight>