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
2901 – Data Pal
(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> from collections import defaultdict def este_palindrom(data): return data == data[::-1] def citeste_date_din_fisier(cale_fisier): try: with open(cale_fisier, "r") as f: nr_date = int(f.readline().strip()) date_agenda = [f.readline().strip() for _ in range(nr_date)] except (ValueError, FileNotFoundError): return None # Returnăm None dacă nu se pot citi datele din fișier return date_agenda def gaseste_secole_cu_cele_mai_multe_date_palindromice(date_palindromice): secole_aparitii = defaultdict(list) for data in date_palindromice: an = int(data[4:]) secol = an // 100 + 1 secole_aparitii[secol].append(an) max_count = max(len(aparitii) for aparitii in secole_aparitii.values()) secole_max_count = sorted([secol for secol, aparitii in secole_aparitii.items() if len(aparitii) == max_count]) return secole_max_count def main(): date_agenda = citeste_date_din_fisier("datapalin.txt") if date_agenda is None or any(len(data) != 8 for data in date_agenda): with open("datapalout.txt", "w") as f_output: f_output.write("Datele de intrare nu corespund cerintelor impuse\n") else: # Câte date palindromice au fost găsite date_palindromice = [data for data in date_agenda if este_palindrom(data)] numar_date_palindromice = len(date_palindromice) # Găsește secolele cu cele mai multe date palindromice secole_max_count = gaseste_secole_cu_cele_mai_multe_date_palindromice(date_palindromice) # Scrie rezultatele în fișierul de ieșire with open("datapalout.txt", "w") as f_output: f_output.write("Datele de intrare corespund cerintelor impuse\n") f_output.write(str(numar_date_palindromice) + "\n") f_output.write(" ".join(map(str, secole_max_count))) 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