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
1264 - StatisticiOrdine
(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 ver. 1 === <syntaxhighlight lang="python" line> # 1264 - Statistici Ordine def validare_date_numar(numar_elemente: str, numar_dorit: str) -> bool: try: int(numar_elemente), int(numar_dorit) if 1 <= int(numar_elemente) <= 4_000_000 and int(numar_dorit) <= int(numar_elemente): return True else: raise ValueError except ValueError: return False def validare_date_sir(lista: list) -> bool: return all(0 <= int(element) < 4_000_000_000 for element in lista) def partition(arr: list, low: int, high: int): pivot = arr[high] indice1 = low - 1 for indice2 in range(low, high): if arr[indice2] <= pivot: indice1 += 1 arr[indice1], arr[indice2] = arr[indice2], arr[indice1] arr[indice1 + 1], arr[high] = arr[high], arr[indice1 + 1] return indice1 + 1 def quicksort(arr: list, low: int, high: int): if low < high: poz = partition(arr, low, high) quicksort(arr, low, poz - 1) quicksort(arr, poz + 1, high) def statistici_ordine(arr: list, numar_elemente: int, pozitie: int) -> int: quicksort(arr, 0, numar_elemente - 1) return arr[pozitie - 1] if __name__ == "__main__": file_input = open("statisticiordine.in", "r") file_output = open("statisticiordine.out", "w") line1 = file_input.readline() line1 = line1.split(" ") numar_elemente = line1[0] numar_dorit = line1[1] if validare_date_numar(numar_elemente, numar_dorit): numar_elemente, numar_dorit = int(numar_elemente), int(numar_dorit) line2 = file_input.readline() arr = line2.split(" ") if validare_date_sir(arr): arr = list(map(int, arr)) print("Datele de intrare corespund restricțiilor impuse.") file_output.write(str(statistici_ordine(arr, numar_elemente, numar_dorit))) else: print("Datele de intrare nu corespund restricțiilor impuse.") else: print("Datele de intrare nu corespund restricțiilor 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