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
4253 - Text OJI
(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"> def aliniere_stanga_dreapta(max_lungime, paragraf): # Verificăm condițiile impuse asupra datelor de intrare if not (2 <= max_lungime <= 1000): raise ValueError("Max trebuie să fie între 2 și 1000.") cuvinte_paragraf = paragraf.split() if any(len(cuvant) > 50 for cuvant in cuvinte_paragraf): raise ValueError("Lungimea maximă a oricărui cuvânt nu trebuie să depășească 50 de caractere.") if len(paragraf) > 1000: raise ValueError("Lungimea totală a paragrafului nu trebuie să depășească 1000 de caractere.") linii = [] for linie in paragraf.split("\n"): cuvinte = linie.split() linie_curenta = cuvinte[0] for cuvant in cuvinte[1:]: if len(linie_curenta) + len(cuvant) + 1 <= max_lungime: linie_curenta += " " + cuvant else: linii.append(linie_curenta.ljust(max_lungime)) linie_curenta = cuvant linii.append(linie_curenta.ljust(max_lungime)) return "\n".join(linii) if __name__ == "__main__": # Citim datele de intrare din fișierul "textoji.in" with open("textojiin.txt", "r") as f_in: max_lungime = int(f_in.readline().strip()) text = f_in.read() # Apelăm funcția pentru aliniere try: rezultat = aliniere_stanga_dreapta(max_lungime, text) except ValueError as e: print(f"Eroare: {str(e)}") else: # Scriem rezultatul în fișierul "textoji.out" with open("textojiout.txt", "w") as f_out: f_out.write(rezultat) </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