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
0317 - SumMax
(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!
= Exemplul 2 = <code>summaxIN.txt</code> 100000 consola Nu corespunde restricțiilor == Rezolvare == <syntaxhighlight lang="python3" line="1"> def citeste_matrice(file_path): with open(file_path, 'r', encoding='utf-8') as file: n = int(file.readline().strip()) matrice = [list(map(int, file.readline().split())) for _ in range(n)] return n, matrice def scrie_rezultat(file_path, rezultat): with open(file_path, 'w', encoding='utf-8') as file: file.write(str(rezultat)) def verifica_restrictii(n, matrice): if not (1 <= n <= 10): return False for linie in matrice: for element in linie: if not (0 <= element <= 9999): return False return True def gaseste_suma_maxima(n, matrice): elemente_sortate = sorted([(matrice[i][j], i, j) for i in range(n) for j in range(n)], reverse=True) linii_selectate = set() coloane_selectate = set() suma_maxima = 0 for element, i, j in elemente_sortate: if i not in linii_selectate and j not in coloane_selectate: suma_maxima += element linii_selectate.add(i) coloane_selectate.add(j) return suma_maxima if __name__ == "__main__": fisier_intrare = "summaxIN.txt" fisier_iesire = "summaxOUT.txt" n, matrice = citeste_matrice(fisier_intrare) if verifica_restrictii(n, matrice): rezultat = gaseste_suma_maxima(n, matrice) if rezultat > 0: scrie_rezultat(fisier_iesire, rezultat) else: scrie_rezultat( "Nu corespunde restrictiilor".encode('utf-8')) else: scrie_rezultat(fisier_iesire, "Nu corespunde restricțiilor".encode('utf-8').decode('utf-8')) </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