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
0969 - Culori1
(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> #0969 - Culori1 def validare_date_intrare(n, m, t, culori): if not (2 <= n < 50 and 2 <= m < 50): return False if not (1 <= t <= 2300000): return False if len(culori) != n: return False for linie in culori: if len(linie) != m: return False if not all(caracter in {'r', 'a'} for caracter in linie): return False return True def modifica_culori(n, m, t, culori): directii = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def numar_vecini(x, y): vecini_rosii = 0 vecini_albastri = 0 for dx, dy in directii: nx, ny = x + dx, y + dy if 0 <= nx < n and 0 <= ny < m: if culori[nx][ny] == 'r': vecini_rosii += 1 elif culori[nx][ny] == 'a': vecini_albastri += 1 return vecini_rosii, vecini_albastri def actualizeaza_culoare(x, y): vecini_rosii, vecini_albastri = numar_vecini(x, y) if vecini_rosii > vecini_albastri: return 'r' elif vecini_rosii < vecini_albastri: return 'a' else: return culori[x][y] for _ in range(t): noua_culoare = [[''] * m for _ in range(n)] for i in range(n): for j in range(m): noua_culoare[i][j] = actualizeaza_culoare(i, j) culori = [''.join(row) for row in noua_culoare] return culori if __name__ == "__main__": with open("culori1in.txt", "r") as fin: n, m, t = map(int, fin.readline().split()) culori = [fin.readline().strip() for _ in range(n)] if validare_date_intrare(n, m, t, culori): print("Datele de intrare corespund restricțiilor impuse") rezultat = modifica_culori(n, m, t, culori) with open("culori1out.txt", "w") as fout: fout.write('\n'.join(rezultat)) else: print("Datele de intrare NU corespund restricțiilor impuse") exit(0) </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