Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0635 - Vecini 1
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rezolvare== <syntaxhighlight lang="python" line="1"> def citire_matrice(): # Deschide fișierul de intrare și citește n, m și p with open("vecini1.in", "r") as fin: line = fin.readline().split() if len(line) != 2: print("Datele nu sunt conform restrictiilor impuse.") exit() n, m = map(int, line) if not (1 <= n <= 100 and 1 <= m <= 100): print("Datele nu sunt conform restrictiilor impuse.") exit() matrice = [] # Citește matricea din fișierul de intrare for i in range(n): row = list(map(int, fin.readline().split())) # Verifică dacă elementele matricei sunt conform cerințelor if not all(x <= 1000000 for x in row): print("Datele nu sunt conform restrictiilor impuse.") exit() matrice.append(row) return n, m, matrice def vecini1(n, m, matrice): a = [[0] * (m + 2) for i in range(n + 2)] cnt = 0 # Adăugarea de margini de numere mari în matrice for i in range(1, n + 1): for j in range(1, m + 1): a[i][j] = matrice[i-1][j-1] a[i][0] = 1000001 a[i][m + 1] = 1000002 for j in range(1, m + 1): a[0][j] = 1000003 a[n + 1][j] = 1000004 # Parcurgerea matricei pentru a verifica vecinii for i in range(1, n + 1): for j in range(1, m + 1): if a[i][j - 1] != a[i][j + 1] and a[i][j - 1] != a[i - 1][j] and a[i][j - 1] != a[i + 1][j] and a[i][j + 1] != a[i - 1][j] and a[i - 1][j] != a[i + 1][j] and a[i][j + 1] != a[i + 1][j]: cnt += 1 return cnt if _name_ == "_main_": n, m, matrice = citire_matrice() col_divizibile = vecini1(n, m, matrice) with open("vecini1.out", "w") as fout: fout.write(str(col_divizibile) + "\n") print("Numarul de elemente cu toti vecinii diferiti intre ei este:", col_divizibile) </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width