affiche juste le code, pas d'explications !
- User
System: affiche juste le code, pas d'explications ! User: Tu es un développeur python3 expérimenté, et tu dois concevoir un programme en python (avec des commentaires en français, sans utiliser de librairies externes, sans
if __name__=="__main__":, avec type hints, et en privilégiant les algorythmes a complexité constante (O(1)) et/ou complexité linéaire (O(n))). Le programme va recevoir les données en entrée sur la stdin, et doit répondre sur la stdout. Fabrique moi un programme python qui résout le problème (énoncé en markdown) suivant :Medal Table
The Games can finally begin, but one question is on everyone's mind: Which country is currently leading the medal standings?
You know the number of medals each country has, and your goal is to determine which one is in the first place.
The ranking is based on the number of gold medals, followed by silver, and then bronze.
There will never be a tie for first place.
Data
Input
Line 1: an integer
N, the number of countries (1 <=N<= 100).The next
Nlines: each contains, separated by spaces:Cthe name of the country,Gthe number of gold medals,Sthe number of silver medals, andBthe number of bronze medals.The country name does not contain spaces and is between 1 and 30 characters in length. The medal counts are integers between 0 and 1000.
Output
The name of the country at the top of the medal standings.
Example 1
For the input:
plaintext5 Italie 12 13 15 Japon 20 12 13 Republique-de-Coree 13 9 10 Allemagne 12 13 8 France 16 26 22The country at the top of the standings is:
plaintextJaponExplanation:
Japan has the most gold medals.
Example 2
For the input:
plaintext7 Singapour 2 1 0 Iran 8 10 7 Ouzbekistan 10 9 7 Tunisie 5 3 3 Suisse 8 8 5 Canada 10 9 10 Ethiopie 2 1 0The country at the top of the standings is:
plaintextCanadaExplanation:
- Assistantpython
# Lecture des données d'entrée depuis stdin import sys input = sys.stdin.read def trouver_pays_en_tete(data: str) -> str: # Séparer les lignes d'input lignes = data.strip().split('\n') # Nombre de pays N = int(lignes[0]) # Initialiser le meilleur pays et son score maximum meilleur_pays = "" max_score = (-1, -1, -1) # Triple pour stocker (Or, Argent, Bronze) # Parcourir chaque ligne pour obtenir les détails de chaque pays for i in range(1, N + 1): # Extraire le pays et le nombre de médailles pays_info = lignes[i].split() pays = pays_info[0] or_count = int(pays_info[1]) argent_count = int(pays_info[2]) bronze_count = int(pays_info[3]) # Comparer selon les règles énoncées : Or > Argent > Bronze score = (or_count, argent_count, bronze_count) # Vérifier si le score actuel est supérieur au score maximum if score > max_score: max_score = score meilleur_pays = pays # Retourner le pays en tête return meilleur_pays # Appel de la fonction avec les données d'entrée data = input() resultat = trouver_pays_en_tete(data) print(resultat)