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
0123 - Permutari
(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!
==Exemplu== ===Exemplul 1=== ; permutari.in : 4 ; Date de ieșire : Datele introduse corespund cerințelor. ; permutari.out :1 2 3 4 :1 2 4 3 :1 3 2 4 :1 3 4 2 :1 4 2 3 :1 4 3 2 :2 1 3 4 :2 1 4 3 :2 3 1 4 :2 3 4 1 :2 4 1 3 :2 4 3 1 :3 1 2 4 :3 1 4 2 :3 2 1 4 :3 2 4 1 :3 4 1 2 :3 4 2 1 :4 1 2 3 :4 1 3 2 :4 2 1 3 :4 2 3 1 :4 3 1 2 : 4 3 2 1 === Exemplul 2 === ;permutari.in :0 ;Date de ieșire :Datele introduse nu corespund cerințelor. ;permutari.out : ===Exemplul 3=== ;permutari.in :bau bau ;Date de ieșire :Datele introduse nu corespund cerințelor. ;permutari.out : ===Rezolvare=== <syntaxhighlight lang="python" line=""> #0123 import sys #functia care valideaza daca numarul din fisierul de intrare este un numar intreg pozitiv intre 1 si 10 def validare_numar_intreg_pozitiv(input_file, output_file, mesaj): numar = -1 while numar <= 0 or numar > 10: try: numar = int(input_file.readline().strip()) if numar <= 0 or numar > 10: print("Datele introduse nu corespund cerintelor.\n") sys.exit() # program stops here else: print("Datele introduse corespund cerintelor.\n") return numar except ValueError: print("Introduceti un numar intreg pozitiv.\n") sys.exit() # program stops here #functia care verifica daca elementele multimi sunt unice def Ok(index): for i in range(1,index): if multime[index]==multime[i]: return 0 return 1 #functia care gaseste toate permutarile de n elemente si le scrie in fisierul de iesire def back(index): with open('permutari.out', 'a') as output_file: for i in range(1, n + 1): multime[index] = i if Ok(index): if index == n: for j in range(1, n + 1): output_file.write(str(multime[j])) if j < n: output_file.write(" ") output_file.write("\n") else: back(index + 1) if __name__ == '__main__': with open('permutari.in', 'r') as input_file, open('permutari.out', 'w') as output_file: n = validare_numar_intreg_pozitiv(input_file, output_file, "Dați numărul:\n") multime = [None] * 11# se initializeaza o lista in care se vor stoca elementele multimii back(1)# se apeleaza functia back pentru a gasi permutarile multimii </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