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
1611 - Palindrom 2
(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> # 1611 def verifica_datele(numar, numere): if numar < 1 or numar > 10000: return False if len(numere) != numar: return False for nr in numere: if nr < 1 or nr > 2000000000: return False return True def este_palindrom(nr): nr_str = str(nr) return nr_str == nr_str[::-1] def este_aproape_palindrom(nr): nr_str = str(nr) cifre = {} for cifra in nr_str: cifre[cifra] = cifre.get(cifra, 0) + 1 doua_cifre = 0 o_cifra = 0 for cifra, aparitii in cifre.items(): if aparitii >= 2: if aparitii % 2 == 0: doua_cifre += 1 else: o_cifra += 1 if doua_cifre > 1 or o_cifra > 1: return False return True if __name__ == '__main__': with open('palindrom2.in', 'r') as f: c = int(f.readline()) numar = int(f.readline()) numere = list(map(int, f.readline().split())) if verifica_datele(numar, numere): if c == 1: nr_palindroame = sum(1 for nr in numere if este_palindrom(nr)) with open('palindrom2.out', 'w') as g: g.write(str(nr_palindroame)) elif c == 2: nr_aproape_palindroame = sum(1 for nr in numere if este_aproape_palindrom(nr)) with open('palindrom2.out', 'w') as g: g.write(str(nr_aproape_palindroame)) elif c == 3: palindroame_asociate = [] for nr in numere: i = nr + 1 while not este_palindrom(i): i += 1 palindroame_asociate.append(i) with open('palindrom2.out', 'w') as g: g.write(' '.join(str(p) for p in palindroame_asociate)) else: print("Datele nu au fost introduse corect.") </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