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
0995 - Numere 6
(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"> # 0995 Numere 6 def verificare(nr1, nr2): # functia de verificare a datelor de intrare if nr1 > 2000000 or nr2 > 2000000: # daca numerele nu respecta restrictia vom ridica eroarea Value Error raise ValueError return True def numere6(nr_1, nr_2): # functia de rezolvare frecventa_cifre = [] # folosim vectorul de frecventa pentru a retine ce cifre avem for i in range(10): frecventa_cifre.append(0) while nr_1: # aflam frecventa cifrelor primului numar u_cif = int(nr_1 % 10) frecventa_cifre[u_cif] += 1 nr_1 //= 10 while nr_2: # acum adaugam si frecventa cifrelor celui de-al doilea numar u_cif = int(nr_2 % 10) frecventa_cifre[u_cif] += 1 nr_2 //= 10 # in vectorul de frecventa avem memorat de cate ori apare fiecare cifra for cifra in range(9, -1, -1): # luam cifrele in ordine inversa din vectorul de frecventa while frecventa_cifre[cifra]: # de cate ori apare cifra respectiva o afisam frecventa_cifre[cifra] -= 1 file_out.write(str(cifra)) if __name__ == '__main__': file_in = open("numere6in.txt") # declararea fisierelor file_out = open("numere6out.txt", "w") # fisierul de iesire declarat cu "write" numere = file_in.readline().split() try: # ne asteptam la eroarea ValueError cauzata de datele de intrare numar_1 = int(numere[0]) # transformam numerele in int numar_2 = int(numere[1]) # daca nu se pot transforma in int atunci va fi o eroare ValueError verificare(numar_1, numar_2) # apelul functiei de verificare numere6(numar_1, numar_2) # apelul functiei de rezolvare except ValueError: print("Datele de intrare nu corespund restricțiilor 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