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
4050 - amongus
(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="python3" line="1"> def numar_cabine_sigure(matrice, n, m): numar_sigure = 0 for i in range(n): for j in range(m): if matrice[i][j] == 0: numar_sigure += 1 return numar_sigure def marcaza_cabine_sigure(matrice, n, m): for i in range(n): for j in range(m): if matrice[i][j] == 0: matrice[i][j] = 3 def numar_portale_accesibile(matrice, n, m): numar_portale = 0 for i in range(n): for j in range(m): if matrice[i][j] == 2 and not are_impstor_in_jur(matrice, n, m, i, j): numar_portale += 1 return numar_portale def are_impstor_in_jur(matrice, n, m, i, j): for x in range(max(0, i-1), min(n, i+2)): for y in range(max(0, j-1), min(m, j+2)): if matrice[x][y] == 1: return True return False def verificare(rezultat, p, n, m, matrice_initiala): if p == 1: return isinstance(rezultat, int) and 0 <= rezultat <= n * m elif p == 2: if not all(isinstance(row, list) and len(row) == m for row in rezultat): return False if not all(isinstance(elem, int) and 0 <= elem <= 3 for row in rezultat for elem in row): return False for i in range(n): for j in range(m): if matrice_initiala[i][j] == 0 and rezultat[i][j] != 3: return False return True elif p == 3: return isinstance(rezultat, int) and 0 <= rezultat <= n * m # Citire date de intrare with open("amongusin.txt", "r") as file: p = int(file.readline().strip()) n, m = map(int, file.readline().split()) matrice_initiala = [list(map(int, file.readline().split())) for _ in range(n)] # Rezolvare cerinte if p == 1: rezultat = numar_cabine_sigure(matrice_initiala, n, m) elif p == 2: rezultat = matrice_initiala.copy() marcaza_cabine_sigure(rezultat, n, m) elif p == 3: rezultat = numar_portale_accesibile(matrice_initiala, n, m) # Scriere rezultat în fișierul de ieșire with open("amongusout.txt", "w") as file: if p == 1 or p == 3: file.write(str(rezultat) + "\n") elif p == 2: for linie in rezultat: file.write(" ".join(map(str, linie)) + "\n") # Verificare rezultat rezultat_corect = verificare(rezultat, p, n, m, matrice_initiala) print("Rezultat corect:", rezultat_corect) </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