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
3162 - cife bin back
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!
== Cerința == Se dă un număr natural n. Afișați în ordine lexicografică toate secvențele de cifre binare care au atâtea cifre de 0 și atâtea cifre de 1 câte are reprezentarea binară a lui n. == Date de intrare == Programul citește de la tastatură numărul n. == Date de ieșire == Programul va afișa pe ecran combinațiile de cifre binare cerute, câte una pe fiecare rând. == Restricții și precizări == *1 ≤ n ≤ 2.000.000 == Exemplu 1 == ;Intrare 17 ;Iesire 00011<br> 00101<br> 00110<br> 01001<br> 01010<br> 01100<br> 10001<br> 10010<br> 10100<br> 11000 == Rezolvare == <syntaxhighlight lang="python" line> from itertools import permutations def generate_binary_sequences(n): binary_representation = bin(n)[2:] count_ones = binary_representation.count('1') count_zeros = len(binary_representation) - count_ones # Create the base string with the correct number of 1s and 0s base_string = '1' * count_ones + '0' * count_zeros # Generate all unique permutations of the base string unique_permutations = sorted(set(permutations(base_string))) # Convert tuples back to strings result = [''.join(p) for p in unique_permutations] return result def main(): n = int(input().strip()) results = generate_binary_sequences(n) for result in results: print(result) 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