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
0124 - Permutari1
(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 1 = <code>permutari1IN.txt</code> 3 <code>permutari1OUT.txt</code> 3 2 1 3 1 2 2 3 1 2 1 3 1 3 2 1 2 3 == Exemplul 2 == <code>permutari1IN.txt</code> 10 consola Eroare: Numărul n trebuie să fie în intervalul (0, 9). == Rezolvare == <syntaxhighlight lang="python3" line="1"> def verifica_restrictii(n): if not (0 < n < 9): print("Eroare: Numărul n trebuie să fie în intervalul (0, 9).") return False return True def generate_permutations(n, current_permutation, output_file): if len(current_permutation) == n: output_file.write(" ".join(map(str, current_permutation[::-1])) + "\n") return for i in range(1, n + 1): if i not in current_permutation: generate_permutations(n, current_permutation + [i], output_file) def main(): with open("permutari1IN.txt", "r") as f: linie = f.readline().strip() if not linie: print("Eroare: Fișierul de intrare este gol sau conține doar linii goale.") return try: n = int(linie) except ValueError: print("Eroare: Numărul n nu poate fi convertit la întreg. Asigurați-vă că fișierul de intrare este formatat corect.") return if not verifica_restrictii(n): return with open("permutari1OUT.txt", "w") as output_file: generate_permutations(n, [], output_file) if __name__ == "__main__": main() </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