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
1001 - Rotund
(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!
= Restricţii şi precizări = * <code>1 ≤ n ≤ 50</code> * elementele şirului vor avea cel mult <code>10</code> cifre == Exemplul 1 == rotundIN.txt: 5 12 3232 123 144144 77 rotundOUT.txt: 3 3232 144144 77 == Exemplul 2 == rotundIN.txt: 0 12 3232 123 144144 77 Output consola: Numărul n trebuie să fie între 1 și 50. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def validate_input(n, sir): # Verificare pentru n if not (1 <= n <= 50): print("Numărul n trebuie să fie între 1 și 50.") return False # Verificare pentru fiecare element din șir for x in sir: if not (1 <= x <= 999999999): print("Elementele șirului trebuie să fie numere naturale cu cel mult 10 cifre.") return False return True def rotund(numar): str_numar = str(numar) numar_cifre = len(str_numar) for i in range(1, numar_cifre): permutare = int(str_numar[-i:] + str_numar[:-i]) if permutare == numar: return True return False def main(): # Citire date de intrare din fisier with open("rotundIN.txt", "r") as f: n = int(f.readline()) sir = list(map(int, f.readline().split())) # Verificare validitate input if not validate_input(n, sir): return # Identificare și afișare elemente rotunde din șir rotunde = [x for x in sir if rotund(x)] numar_rotunde = len(rotunde) # Scriere rezultat in fisier with open("rotundOUT.txt", "w") as f: f.write(str(numar_rotunde) + "\n") if numar_rotunde > 0: f.write(" ".join(map(str, rotunde))) 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