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
0554 - Marte
(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=""> #0554 - Marte # defineste o functie ce calculeaza suma valorii monedelor, pentru fiecare martian def calculeaza_suma(valori_monede, numar_monede): suma = 0 for i in range(len(valori_monede)): suma += valori_monede[i] * numar_monede[i] return suma # defineste o functie ce gaseste cel mai bogat martian, bazat pe suma valorii mondelor pe care le au def cel_mai_bogat_martian(n, valori_monede, m, info_martieni): cel_mai_bogat = 1 # initializeaza maximul sumei pentru valorile monedelor suma_maxima = calculeaza_suma(valori_monede, info_martieni[0]) for i in range(1, m): # calculeaza suma valorii monedelor pentru martianul curent suma_curenta = calculeaza_suma(valori_monede, info_martieni[i]) # daca suma valorii monedelor pentru martianul curent e mai mare decat maximul sumei, # face update cu cel mai bogat martian si maximul sumei if suma_curenta > suma_maxima: cel_mai_bogat = i + 1 suma_maxima = suma_curenta return cel_mai_bogat if __name__ == '__main__': # citeste tipurile de monede, valorile lor, numarul martienilor si informatiile despre ei n = int(input("Introduceți numărul de tipuri de monede: ")) valori_monede = list(map(int, input("Introduceți valorile monedelor: ").split())) m = int(input("Introduceți numărul de marțieni: ")) info_martieni = [] for i in range(m): info_martian = list(map(int, input(f"Introduceți numărul de monede pentru marțieni: ").split())) info_martieni.append(info_martian) # verifica daca se respecta restrictiile if n < 1 or n > 50 or m < 1 or m > 1000 or max(valori_monede) > 5000: print("Datele de intrare nu corespund restricțiilor impuse.") else: print("Datele de intrare corespund restricțiilor impuse.") # gaseste cel mai bogat martian X = cel_mai_bogat_martian(n, valori_monede, m, info_martieni) # afiseaza numarul celui mai bogat martian print(f"Cel mai bogat marțian este {X}.") </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