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
0202 - PermPF
(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!
= Exemplul 2 = <code>permpfIN.txt</code> 10 Consola Valoarea lui n nu respectă restricțiile. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def verifica_restrictii_n(n): return 0 < n < 9 def are_puncte_fixe(perm): for i in range(len(perm)): if perm[i] == i + 1: return True return False def backtracking(perm, poz, n, output_file): if poz == n: if not are_puncte_fixe(perm): output_file.write(' '.join(map(str, perm)) + '\n') return for i in range(1, n + 1): if i not in perm: perm[poz] = i backtracking(perm, poz + 1, n, output_file) perm[poz] = 0 def permutari_fara_puncte_fixe(n, output_file): perm = [0] * n backtracking(perm, 0, n, output_file) # Citirea valorii lui n din fișierul de intrare with open("permpfIN.txt", "r") as input_file: line = input_file.readline().strip() if not line: print("Fișierul de intrare este gol sau corupt.") else: try: n = int(line) # Verificăm restricțiile asupra valorii lui n if verifica_restrictii_n(n): # Deschiderea fișierului de ieșire with open("permpfOUT.txt", "w") as output_file: # Apelăm funcția pentru generarea permutărilor fără puncte fixe permutari_fara_puncte_fixe(n, output_file) else: print("Valoarea lui n nu respectă restricțiile.") except ValueError: print("Linia citită din fișier nu reprezintă un număr întreg valid.") </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