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
1059 - Schimb Cifre
(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!
== Rezolvare == <syntaxhighlight lang="python" line> #1059 from typing import List, Tuple # Funcție de verificare a datelor conform restricțiilor def verificare_date(n: int, s: int, t: int, interschimbari: List[Tuple[int, int]]) -> bool: # Verificare restricție n if n < 1 or n > 1000000000: return False # Verificare restricție s if s < 1 or s > 2000000000: return False # Verificare restricție t if t < 1 or t > 10: return False # Verificare restricție interschimbari for i, j in interschimbari: if i < 1 or i > len(str(n)) or j < 1 or j > len(str(n)): return False return True # Funcție pentru interschimbarea cifrelor la pozițiile i și j într-un număr def interschimbare_cifre(numar: int, i: int, j: int) -> int: cifre = [int(cifra) for cifra in str(numar)] cifre[i-1], cifre[j-1] = cifre[j-1], cifre[i-1] return int("".join(map(str, cifre))) # Funcția main if __name__ == "__main__": # Citire date de intrare n, s, t = map(int, input("Introduceti datele separate prin spatii: ").split()) interschimbari = [] for i in range(t): i, j = map(int, input("Introduceti datele separate prin spatii: ").split()) interschimbari.append((i, j)) # Verificare date de intrare if not verificare_date(n, s, t, interschimbari): print("Datele introduse nu sunt corecte.") exit() # Efectuare serii de transformări for k in range(s): for i, j in interschimbari: if i > j: i, j = j, i n = interschimbare_cifre(n, i, j) # Afișare rezultat print("Datele introduse sunt corecte.") print(n) </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