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
0417 - Grad Max
(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="python3" line="1"> def citeste_graf(file_path): with open(file_path, 'r') as file: n = int(file.readline().strip()) # Verifica restricțiile pentru numărul de vârfuri if not (1 <= n <= 100): return None, None, "Datele nu corespund restrictiilor impuse" muchii = [tuple(map(int, line.strip().split())) for line in file] # Verifica restricțiile pentru vârfurile muchiilor for i, j in muchii: if not (1 <= i <= n) or not (1 <= j <= n): return None, None, "Datele nu corespund restrictiilor impuse" return n, muchii, None def calculeaza_grad(n, muchii): grad = [0] * (n + 1) for i, j in muchii: grad[i] += 1 grad[j] += 1 return grad def vafuri_grad_maxim(grad): max_grad = max(grad) vafuri_maxime = [i for i, val in enumerate(grad) if val == max_grad] return vafuri_maxime def scrie_output(file_path, vafuri_maxime, eroare=None): with open(file_path, 'w') as file: if eroare: file.write(eroare) else: file.write(f"{len(vafuri_maxime)}\n") file.write(" ".join(map(str, vafuri_maxime))) if __name__ == "__main__": file_input = "gradmaxIN.txt" file_output = "gradmaxOUT.txt" n, muchii, eroare = citeste_graf(file_input) scrie_output(file_output, [], eroare) if eroare else None if not eroare: grad = calculeaza_grad(n, muchii) vafuri_maxime = vafuri_grad_maxim(grad) scrie_output(file_output, vafuri_maxime) </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