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
0987 - Matrice 4
(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!
= Restricții și precizări = * <code>1 ≤ n ≤ 100</code> * elementele matricei sunt numere naturale mai mici decât <code>1 000 000</code> * liniile matricei sunt numerotate de la <code>1</code> la <code>n</code>. == Exemplul 1 == Input: 4 1 2 3 4 1 1 1 2 2 2 41 8 3 3 10 2 Output: 1 4 == Exemplul 2 == Input: 51 1 2 3 1 2 3 1 2 3 Output consola: Dimensiunea n nu respecta restrictiile. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def suma(x, n, p): # Implementarea subprogramului suma return sum(x[p-1]) def verificare_dimensiune_n(n): # Verifică restricțiile pentru dimensiunea n return 1 <= n <= 100 def verificare_elemente_matrice(matrice): # Verifică restricțiile pentru elementele matricei for linie in matrice: for elem in linie: if not (0 <= elem < 1000000): return False return True def main(): # Citirea datelor de intrare din fisierul matrice4.in with open("matriceIN.txt", "r") as file_in: n = int(file_in.readline().strip()) matrice = [list(map(int, file_in.readline().split())) for _ in range(n)] # Verificarea restricțiilor pentru dimensiunea n if not verificare_dimensiune_n(n): print("Dimensiunea n nu respecta restrictiile.") return # Verificarea restricțiilor pentru elementele matricei if not verificare_elemente_matrice(matrice): print("Elementele matricei nu respecta restrictiile.") return # Determinarea indiciilor liniilor cu suma elementelor număr par linii_par = [i+1 for i in range(n) if suma(matrice, n, i+1) % 2 == 0] # Scrierea rezultatului în fisierul matrice4.out with open("matriceOUT.txt", "w") as file_out: file_out.write(" ".join(map(str, linii_par))) 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