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
0275 - Perechi Vocale 1
(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="1"> # 0275 Perechi Vocale 1 def validare(lista_prop): # functia de validare a datelor de intrare for prop in lista_prop: for caracter in prop: if 'A' <= caracter <= 'Z': # sirul nu poate contine majuscule raise ValueError # daca datele de intrare nu corespund, ridicam eroarea ValueError for prop in lista_prop: cuvinte_din_propozitie = prop.split() for cuvant in cuvinte_din_propozitie: if len(cuvant) > 40: raise ValueError file_out.write("Datele de intrare corespund restrictiilor impuse\n") def vocala(litera): # functie care verifica daca litera e sau nu vocala if litera in "aeiou": return True return False def perechi_vocale_1(lista_prop): # functia de rezolvare lista_perechi_vocale = [] # adaugam perechile de vocale intr-o lista for prop in lista_prop: for index in range(len(prop)-1): # parcurgem caracterele din fiecare propozitie 2 cate 2 si verificam daca sunt perechi de vocale caracter_curent = prop[index] caracter_urmator = prop[index+1] if vocala(caracter_curent) == vocala(caracter_urmator) and vocala(caracter_urmator) is True: lista_perechi_vocale.append(caracter_curent + caracter_urmator) # daca sunt vocale adaugam perechea in lista lista_perechi_vocale_distinct = list(set(lista_perechi_vocale)) # creem o lista in care fiecare pereche de vocale apare o singura data si o sortam lexicografic lista_perechi_vocale_distinct.sort() maxim_aparitii = 0 for pereche in lista_perechi_vocale_distinct: # folosind lista de perechi distincte vedem care e numarul maxim de aparitii a fiecarei perechi # in lista principala de perechi vocale nr_aparitii = lista_perechi_vocale.count(pereche) if nr_aparitii > maxim_aparitii: maxim_aparitii = nr_aparitii lista_perechi_maxime = [] # creem o lista pentru perechile de vocale ce apar cel mai des for pereche in lista_perechi_vocale_distinct: nr_aparitii = lista_perechi_vocale.count(pereche) if nr_aparitii == maxim_aparitii: # daca gasim o pereche cu numar maxim de aparitii o adaugam in lista lista_perechi_maxime.append(pereche) if len(lista_perechi_maxime) > 0: for pereche in lista_perechi_maxime: # afisam fiecare pereche maxima file_out.write(pereche + " ") else: file_out.write("NU") # daca nu exista afisam mesajul NU if __name__ == '__main__': file_in = open("perechivocale1in.txt", "r") # declararea fisierelor file_out = open("perechivocale1out.txt", "w") # fisierul out trebuie declarat cu optiunea "w" (write) # din cauza datelor de intrare pot aparea 2 tipuri de erori, valueError sau IndexError pe care le tratam try: lista_propozitii = [] # creem o lista cu fiecare propozitie ce urmeaza sa fie citita for linie in file_in: propozitie = linie.strip() # adaugam propozitia din care eliminam whitespace-urile de la final lista_propozitii.append(propozitie) validare(lista_propozitii) # apelul functiei de validare perechi_vocale_1(lista_propozitii) # apelul functiei de rezolvare except ValueError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") except IndexError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") </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