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
1395 - MSuma
(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 citeste_matrice(fisier): # Citeste dimensiunile matricei n, m = map(int, fisier.readline().split()) matrice = [] # Citeste elementele matricei for _ in range(n): linie = list(map(int, fisier.readline().split())) matrice.append(linie) return matrice, n, m def este_input_valid(n1, m1, n2, m2): return 1 <= n1 <= 100 and 1 <= m1 <= 100 and 1 <= n2 <= 100 and 1 <= m2 <= 100 def suma_matricelor(matrice1, n1, m1, matrice2, n2, m2): if n1 != n2 or m1 != m2: raise ValueError("Dimensiunile matricelor nu corespund") matrice_suma = [[0] * m1 for _ in range(n1)] for i in range(n1): for j in range(m1): matrice_suma[i][j] = matrice1[i][j] + matrice2[i][j] return matrice_suma, n1, m1 def scrie_matrice(fisier, matrice, n, m): fisier.write(f"{n} {m}\n") for linie in matrice: fisier.write(" ".join(map(str, linie)) + "\n") def main(): # Citirea datelor de intrare din fisier with open("msumain.txt", "r") as f: n1, m1 = map(int, f.readline().split()) matrice1, _, _ = citeste_matrice(f) n2, m2 = map(int, f.readline().split()) matrice2, _, _ = citeste_matrice(f) # Verificare validitate date de intrare if not este_input_valid(n1, m1, n2, m2): print("Datele introduse nu corespund restrictiilor impuse.") return # Calcularea sumei matricelor try: matrice_suma, n_suma, m_suma = suma_matricelor(matrice1, n1, m1, matrice2, n2, m2) # Scrierea rezultatului รฎn fisierul de iesire with open("msumaout.txt", "w") as g: scrie_matrice(g, matrice_suma, n_suma, m_suma) except ValueError as e: print(f"EROARE: {e}") if __name__ == "__main__": main() </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