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
3157 - cifre c1c2
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 citesc două cifre diferite c1 și c2 (nenule). Afișați în ordine crescătoare toate numerele care conțin exact c1 cifre egale cu c2 și c2 cifre egale cu c1. == Date de intrare == Programul citește de la tastatură cifrele c1 și c2 separate printr-un spațiu. == Date de ieșire == Programul va afișa pe ecran numerele cerute, câte unul pe un rând. == Restricții și precizări == *1 ≤ c1, c2 ≤ 9 *c1 ≠ c2 == Exemplu 1 == ;Intrare 2 3 ;Iesire 22233<br> 22323<br> 22332<br> 23223<br> 23232<br> 23322<br> 32223<br> 32232<br> 32322<br> 33222 == Rezolvare == <syntaxhighlight lang="python" line> def generate_numbers(c1, c2): from itertools import permutations c1 = str(c1) c2 = str(c2) digits = c1 * int(c2) + c2 * int(c1) permutations_set = set() for perm in permutations(digits): number = ''.join(perm) if number.count(c1) == int(c2) and number.count(c2) == int(c1): permutations_set.add(number) sorted_numbers = sorted(permutations_set) return sorted_numbers def main(): c1, c2 = map(int, input().strip().split()) results = generate_numbers(c1, c2) 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