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
0866 - Acces
(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" start="1"> from collections import deque def validare(n_linii, m_coloane, matrice): # functia de validare a datelor de intrare if n_linii > 1000 or m_coloane > 1000: raise ValueError for linie in matrice: if len(linie) != m_coloane: # fiecare linie trebuie sa aiba lungimea m raise ValueError file_out.write("Datele de intrare corespund restrictiilor impuse\n") def acces(nr, nc, matrice): # functia de rezolvare dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] dist = [[-1]*nc for _ in range(nr)] q = deque() for i in range(nr): for j in range(nc): if matrice[i][j] == 'P': q.append((i, j)) dist[i][j] = 0 while q: x, y = q.popleft() for d in range(4): nx, ny = x + dx[d], y + dy[d] if 0 <= nx < nr and 0 <= ny < nc and matrice[nx][ny] != '#' and dist[nx][ny] == -1: dist[nx][ny] = dist[x][y] + 1 q.append((nx, ny)) for i in range(nr): for j in range(nc): file_out.write(str(dist[i][j]) + ' ') file_out.write('\n') if __name__ == '__main__': file_in = open("accesin.txt", "r") # declararea fisierelor file_out = open("accesout.txt", "w") # fisierul out trebuie declarat cu optiunea "w" (write) # din cauza datelor de intrare pot aparea 2 tipuri de erori, valueError sau IndexError pe care le tratam try: n, m = map(int, file_in.readline().split()) # citirea numarului de linii si coloane mat = [list(file_in.readline().strip()) for _ in range(n)] # citirea matricei validare(n, m, mat) # apelul functiei de validare acces(n, m, mat) # apelul functiei de rezolvare except ValueError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") except IndexError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") </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