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
2668 - Comun
(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="1"> # 2668 Comun def validare(nr_elemente, sir_numere1, sir_numere2, sir_numere3): # functia de verificare a datelor de intrare # in cazul in care nu este respectata vreo restrictie, vom marca acest lucru prin eroarea ValueError if nr_elemente > 100000 or nr_elemente <= 1: raise ValueError for numar in sir_numere1: if numar < 0 or numar > 100000000: raise ValueError if nr_elemente != len(sir_numere1): raise ValueError for numar in sir_numere2: if numar < 0 or numar > 100000000: raise ValueError if nr_elemente != len(sir_numere2): raise ValueError for numar in sir_numere3: if numar < 0 or numar > 100000000: raise ValueError if nr_elemente != len(sir_numere3): raise ValueError # sirurile trebuie sa fie si sortate if sir_numere1 != sorted(sir_numere1) or sir_numere2 != sorted(sir_numere2) or sir_numere3 != sorted(sir_numere3): raise ValueError print("Datele de intrare corespund restrictiilor impuse") def comun(sir_numere1, sir_numere2, sir_numere3): sir_comun = [] # am creat o lista noua in care vom adauga doar elementele comune din toate 3 sirurile for numar in sir_numere1: if numar in sir_numere2 and numar in sir_numere3: # verificam ca numarul din sirul 1 sa fie si in 2 si in 3 sir_comun.append(numar) if len(sir_comun) == 0: # daca lungimea sirului este 0 inseamna ca nu am gasit un element comun in toate 3 print(-1) return print(min(sir_comun)) # afisam doar cel mai mic numar (minimul) din sirul de numere comune if __name__ == '__main__': try: n = int(input("Introduceti numarul n: ")) # citirea lui n si a sirurilor sir1 = input("Introduceti sirul 1: ") sir2 = input("Introduceti sirul 2: ") sir3 = input("Introduceti sirul 3: ") sir1 = sir1.split() # sirul citit e sir de caractere, il transformam in lista de int sir1 = list(map(int, sir1)) sir2 = sir2.split() sir2 = list(map(int, sir2)) sir3 = sir3.split() sir3 = list(map(int, sir3)) validare(n, sir1, sir2, sir3) # apelam functia de validare comun(sir1, sir2, sir3) # apelam functia de rezolvare # ne asteptam la 2 tipuri de erori din cauza datelor de intrare, le tratam corespunzator except ValueError: print("Datele de intrare nu corespund restrictiilor impuse") except IndexError: print("Datele de intrare nu corespund restrictiilor impuse") </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