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
0087 - Lungime Maxima
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 == SÄ se scrie un program care citeČte mai multe propoziČii Či determinÄ propoziČia de lungime maximÄ. == Date de intrare == FiČierul de intrare lgmax.in conČine pe prima linie un numÄr natural n, iar pe urmÄtoarele n linii câte o propoziČie alcÄtuitÄ din litere ale alfabetului englez Či spaČii. == Date de ieĹire == FiČierul de ieČire lgmax.out va conČine pe prima linie propoziČia de lungime maximÄ. == RestricĹŁii Ĺi precizÄri == * 0<n<100 * fiecare propoziČie va conČine cel mult 255 de caractere == Exemplu: == '''lgmaxin.txt''' 4 somnoroase pasarele pe la cuiburi se aduna se ascund in ramurele noapte buna '''lgmaxout.txt''' pe la cuiburi se aduna == Rezolvare == <syntaxhighlight lang="python"> def validare_n(valoare): try: n = int(valoare) if 0 < n < 100: return True, n else: return False, None except ValueError: return False, None def validare_propozitie(propozitie): if len(propozitie) <= 255: return True else: return False def main(): # Deschide fiČierul de intrare pentru citire with open('lgmaxin.txt', 'r') as input_file: # CiteČte numÄrul de propoziČii n_valoare = input_file.readline().strip() este_valid_n, n = validare_n(n_valoare) if not este_valid_n: print("Eroare: NumÄrul de propoziČii nu respectÄ condiČiile.") return # IniČializeazÄ o variabilÄ pentru propoziČia de lungime maximÄ propozitie_maxima = "" # Parcurge fiecare propoziČie for _ in range(n): propozitie = input_file.readline().strip() # VerificÄ dacÄ propoziČia curentÄ are lungimea mai mare decât cea maximÄ if validare_propozitie(propozitie) and len(propozitie) > len(propozitie_maxima): propozitie_maxima = propozitie # Deschide fiČierul de ieČire pentru scriere with open('lgmaxout.txt', 'w') as output_file: # Scrie propoziČia de lungime maximÄ ĂŽn fiČierul de ieČire output_file.write(propozitie_maxima) 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