Skip to content

Latest commit

 

History

History
993 lines (804 loc) · 18.5 KB

Level 1.md

File metadata and controls

993 lines (804 loc) · 18.5 KB

✔️ France ioi Correction Python

Corrected exercise from france ioi python.

france_ioi_logo

📋 Table of Contents

  • 1) Hello world!
  • print("Hello world!")
    
  • 2) Presentation
  • print("Coucou !")
    print("Je m'appelle Camthalion")
    print("Ma devise est 'Parler peu mais parler bien'.")
    
  • 3) Map of the mountain
  • print("Tout droit tu grimperas,")
    print("La clé tu trouveras,")
    print("Habile tu seras,")
    print("Quand tu les porteras,")
    print("Et avec le chef tu reviendras !")
    
  • 4) In the thicket
  • from robot import *
    haut()
    haut()
    haut()
    droite()
    droite()
    bas()
    bas()
    droite()
    
  • 5) Stack of cylinders
  • deplacer(1, 3)
    deplacer(1, 2)
    deplacer(3, 2)
    deplacer(1, 3)
    deplacer(2, 3)
    deplacer(2, 1)
    deplacer(3, 2)
    deplacer(1, 3)
    deplacer(2, 3)
    deplacer(1, 2)
    deplacer(3, 1)
    deplacer(3, 2)
    deplacer(1, 3)
    deplacer(2, 1)
    deplacer(3, 1)
    deplacer(3, 2)
    deplacer(1, 2)
    deplacer(1, 3)
    deplacer(2, 3)
    deplacer(2, 1)
    deplacer(3, 2)
    deplacer(3, 1)
    deplacer(2, 1)
    deplacer(2, 3)
    deplacer(1, 2)
    deplacer(1, 3)
    deplacer(2, 3)
    deplacer(1, 2)
    deplacer(3, 2)
    deplacer(3, 1)
    deplacer(2, 1)
    deplacer(2, 3)
    deplacer(1, 2)
    deplacer(1, 3)
    deplacer(2, 3)
    
  • 6) Secret recipe
  • from robot import *
    
    remplir(5)
    transferer(5, 3)
    vider(3)
    transferer(5, 3)
    remplir(5)
    transferer(5, 3)
    

  • 1) Punishment
  • for i in range(135):
       print("Je dois respecter le Grand Sorcier.")
    
  • 2) Basic math
  • for loop in range(13):
       print("9 * 8 = 72")
    
  • 3) Water transportation
  • from robot import *
    
    gauche()
    gauche()
    print("Bonjour, laissez-moi vous aider")
    ramasser()
    for loop in range(32):
       droite()
    deposer()
    
  • 4) The secret of Goma
  • from robot import *
    
    for loop in range(15):
       droite()
       ramasser()
    droite()
    deposer()
    
  • 5) Sisyphus
  • from robot import *
    
    for loop in range(21):
       haut()
       droite()
    for loop in range(21):
       gauche()
       bas()
    
  • 6) Writing page
  • for i in range(30):
       print("a_", end = "")
    print()
    for i in range(30):
       print("b_", end = "")
    print()
    for i in range(30):
       print("c_", end = "")
    
  • 7) Checkers game
  • for loop in range(20):
       for loop in range(20):
          print("OX", end = "")
       print()
       for loop in range(20):
          print("XO", end="")
       print()
    
  • 8) Mount Kailash
  • for loop in range(20):
       for loop in range(20):
          print("OX", end = "")
       print()
       for loop in range(20):
          print("XO", end="")
       print()
    
  • 9) Harvest
  • from robot import *
    
    for loop in range(20):
       for rammaser in range(1):
          ramasser()
       for pas_droite in range(15):
          droite()
       for deposer_raisain in range(1):
          deposer()
       for pas_gauche in range(15):
          gauche()
       
    
  • 10) The Big Event
  • from robot import *
    
    for loop in range(9):
       haut()
    droite()
    
    for howcompt in range(4):
       for b in range(8):
          bas()
       for d in range(1):
          droite()
       for h in range(8):
          haut()
       for d in range(1):
          droite()
    for b in range(9):
       bas()
    for finish in range(9):
       gauche()
    

  • 1) Answer!
  • print(42)
    
  • 2) The eclipse
  • print(12581 - 11937)
    
  • 3) Candy for everyone!
  • print((25 + 30 + 27 + 22 - 8) * 3) 
    
  • 4) Algoreathlon
  • a = 2
    b = 34
    c = 6
    
    print((a + b + c), end =" ")
    print((a + b + c) * 2, end =" ")
    print((a + b + c) * 3, end =" ")
    
  • 5) Playground
  • c = 108
    
    print(c * 108)
    print(c * 4)
    
  • 6) A game of hide and seek
  • for loop in range(100):
       print(loop + 1)
    print("J'arrive !")
    
  • 7) Progress by error
  • print("V")
    print("V")
    print("I")
    print("I")
    print("V")
    print("I")
    print("I")
    
  • 8) Rocket take off
  • for comptage in range(100,-1,-1):
       print(comptage)
    print("Décollage !")
    
  • 9) Invasion of batrachians
  • crapauds = 1337
    
    for loop in range(12):
       crapauds = crapauds * 2
    print(crapauds)
    
  • 10) Fair
  • tir = 1
    bonbon = 0
    
    for loop in range(50):
       bonbon = bonbon + tir
       print(bonbon)
       tir = tir + 1
    
    
  • 11) Race with the kids
  • from robot import *
    
    i = 1               # compteur.
    n = 1    
               # nombre de fois gauche/droite.
    while i < 11:         # boucle (while) tourne 10 fois.
       for y in range(n):
          droite()
       for e in range(1):
          ramasser()
       for y in range(n):
          gauche()
       for e in range(1):
          deposer()
    
       n += 1
       i += 1
    
  • 12) Construction of a pyramid
  • c = 0
    
    for i in range(1):
       c = 17**3
       c = c + 15**3
       c = c + 13**3 
       c = c + 11**3
       c = c + 9**3
       c = c + 7**3
       c = c + 5**3
       c = c + 3**3
       c = c + 1**3
    print(c)
    
  • 13) Multiplication table
  • for j in range(1, 21):
       for c in range(1, 21):
          print(j * c, end= ' ')
       print()
    

  • 1) Harvests
  • lg = int(input(""))
    
    mc = 23 * lg * lg
    print(mc)     
    
  • 2) Spiritual retreat
  • jours = int(input())
    nombreH = jours * 16
    nombreM = nombreH * 60
    nombreS = nombreM * 60
    print (nombreS)
    
  • 3) Age of grandchildren
  • ageCadet = int(input())
    
    ageAine = int(input())
    
    difference = ageAine - ageCadet
    
    print(difference)
    
  • 4) More punishments
  • x = int(input())
    for i in range(x):
        print("Je dois suivre en cours")
    
  • 5) Graduation of thermometers
  • tempMin = int(input())
    tempMax = int(input())
    for i in range(tempMin, tempMax+1):
        print(i)
    
  • 6) Mental math game
  • tempMin = int(input())
    tempMax = int(input())
    for i in range(tempMin, tempMax+1):
        print(i)
    
  • 7) The Great Sale
  • positionDepart = int(input())
    largeurEmplacement = int(input())
    nbVendeurs = int(input())
    
    for i in range(nbVendeurs + 1):
        print(positionDepart + largeurEmplacement * i)
    
  • 8) Livestock
  • nbkarvas = 0
    for i in range(20):
        nbkarvas = nbkarvas + int(input())
    print(nbkarvas)
    
  • 9) Pedestals for statues
  • socle = 0
    largeursol = int(input())
    largeurface = int(input())
    
    for i in range(largeurface, largeursol + 1):
        etage = i * i
        socle += etage
    
    print(socle)
    
  • 10) The most beautiful Karva
  • nbkarvascomp = int(input()) # nombres de karvas
    
    for i in range(nbkarvascomp): # 
       poinds = int(input())
       age = int(input())
       long_des_cornes = int(input())
       hauteur_au_garot = int(input())
       print(long_des_cornes * hauteur_au_garot + poinds)
    

  • 1) Baggage transportation
  • nbpaquets = int(input())
    poids_paquets = int(input())
    poids_total = nbpaquets * poids_paquets
    
    if  poids_total > 105:
       print("Surcharge ! ")
    
  • 2) Kilometer markers
  • debutnombre = int(input())
    finnombre = int(input())
    
    if finnombre - debutnombre >= 0:
       print(finnombre - debutnombre)
    elif debutnombre - finnombre >= 0:
       print(debutnombre - finnombre)
    
  • 3) Decreasing prices
  • heure_arrivé = int(input())
    
    list_prix = [10, 15, 20, 25, 30, 35, 40, 45, 50, 53, 53, 53, 53]
    
    if heure_arrivé == heure_arrivé:
       print(list_prix[heure_arrivé])
    
  • 4) All-out brawl
  • supArignon = int(input())
    supEvaran = int(input())
    
    if supArignon - supEvaran > 10:
       print("La famille Arignon a un champ trop grand")
    elif supEvaran - supArignon > 10:
       print("La famille Evaran a un champ trop grand")
    
  • 5) Boat price
  • age_personne = int(input())
    
    if age_personne >= 21:
       print("Tarif plein") 
    elif age_personne < 21:
       print("Tarif réduit")
    
  • 6) Crossing the bridge
  • de_1 = int(input())
    de_2 = int(input())
    
    somme_de = de_1 + de_2
    
    if somme_de >= 10:
       print("Taxe spéciale !")
       print(36)
    else:
       print("Taxe régulière")
       print(de_1 * 2 + de_2 * 2)
    
  • 7) Tug of war contest
  • nbMembres = int(input())
    
    equipe_1 = 0
    equipe_2 = 0
    
    for i in range(nbMembres):
        equipe_1 += int(input())
        equipe_2 += int(input())
    
    if equipe_1 > equipe_2:
        print("L'équipe 1 a un avantage")
    else:
        print("L'équipe 2 a un avantage")
    print("Poids total pour l'équipe 1 :", equipe_1)
    print("Poids total pour l'équipe 2 :", equipe_2)
    
  • 8) Village password
  • secre_code = int(input())
    
    if secre_code == 64741:
        print("Bon festin !")
    
    if secre_code != 64741:
        print("Allez-vous en !")
    

  • 1) Towns and villages
  • nblieux = int(input())
    villes = 0
    
    for i in range(nblieux):
        nbpopulation = int(input())
        if nbpopulation > 10000:
            villes += 1
    print(villes)
    
  • 2) Schedule for the day
  • posactuelle = int(input())
    nbvillages = int(input())
    villagesproche = 0
    
    for i in range(nbvillages):
        posvillages = int(input())
        distance = posactuelle - posvillages
        if  abs(distance) <= 50:
            villagesproche += 1
    print(villagesproche)
    
  • 3) Longest stage
  • nbjourdemarche = (int(input()))
    maxdistance = 0
    
    for i in range(nbjourdemarche):
        distanceparcouru = int(input())
        if maxdistance < distanceparcouru:
            maxdistance = distanceparcouru
            
    print(maxdistance)
    
  • 4) Calculation of height differences
  • nbmonte_descend = int(input())
    variation_altitude_descente = 0
    variation_altitude_descente_pos = 0
    variation_altitude_montante = 0
    
    for i in range(nbmonte_descend):
        variation_altitude = int(input())
        if variation_altitude > 0:
            variation_altitude_montante += variation_altitude
        elif variation_altitude < 0:
            variation_altitude_descente += variation_altitude
            variation_altitude_descente_pos = abs(variation_altitude_descente)
    
    print(variation_altitude_montante)
    print(variation_altitude_descente_pos)
    
  • 5) Type of trees
  • hauteur = int(input())
    nbfolioles = int(input())
    
    if hauteur <= 5 and nbfolioles >= 8:
        print("Tinuviel")
    elif hauteur >= 10 and nbfolioles >= 10:
        print("Calaelen")
    elif hauteur <= 8 and nbfolioles <= 5:
        print("Falarion")
    elif  hauteur >= 12 and nbfolioles <= 7:
        print("Dorthonion")
    
  • 6) Hostel prices
  • age = int(input())
    poid = int(input())
    
    if age == 60:
        print(0)
    elif age < 10:
        print(5)
    else:
        if poid >= 20:
            print(30 + 10)
        else: 
            print(30)
    
  • 7) Protection of the village
  • nbmaisons = int(input())
    pos_x_min = 1000000
    pos_y_min = 1000000
    pos_x_max = 0
    pos_y_max = 0
    
    for i in range(nbmaisons):
        pos_x = int(input())
        pos_y = int(input())
        if pos_x < pos_x_min:
            pos_x_min = pos_x
        if pos_x > pos_x_max:
            pos_x_max = pos_x
    
        if pos_y < pos_y_min:
            pos_y_min = pos_y
        if pos_y > pos_y_max:
            pos_y_max = pos_y
    
    print(2 * (pos_x_max - pos_x_min + pos_y_max - pos_y_min))
    
  • 8) The right price
  • nbMarchands = int(input())
    minPrix = 1000 * 1000
    posMinPrix = -1
    pos = 1
    for loop in range(nbMarchands):
       prix = int(input())
       if prix <= minPrix:
          minPrix = prix
          posMinPrix = pos
       pos = pos + 1
    print(posMinPrix)
    

  • 1) Alien Spy
  • date_debut = int(input())
    date_fin = int(input())
    
    nbEntrees = int(input())
    
    nb_de_personne_entree = 0
    
    for personne in range(nbEntrees):
        date = int(input())
    
        if date >= date_debut and date <= date_fin:
            nb_de_personne_entree += 1
    
    print(nb_de_personne_entree)
    
  • 2) Spy House
  • abs_min = int(input())
    abs_max = int(input())
    ord_min = int(input())
    ord_max = int(input())
    
    nombre_ttl_maison = int(input())
    
    maisons_dans_la_zone = 0
    
    for maison in range(nombre_ttl_maison):
        abs = int(input())
        ord = int(input())
        
        if abs >= abs_min and abs <= abs_max and ord >= ord_min and ord <= ord_max:
            maisons_dans_la_zone += 1
    
    print(maisons_dans_la_zone)
    
  • 3) Number of days in the month
  • mois = int(input())
    
    if mois >= 1 and mois <= 3 or mois >= 7 and mois <=9:         # tranche de mois | 1 to 3 - 7 to 9.
        print(30)
    elif mois >= 4 and mois <= 6 or mois == 10:         # tranche de mois | 4 to 6 - 10.
        print(31)
    else:                                                # si tout est faux print 29.
        print(29)        
    
    
  • 4) Friendship between guards
  • date_debut_sld1 = int(input())
    date_fin_sld1 = int(input())
    
    date_debut_sld2 = int(input())
    date_fin_sld2 = int(input())
    
    if date_fin_sld1 < date_debut_sld2 or date_fin_sld2 < date_debut_sld1:
        print("Pas amis")
    else:
        print("Amis")
    
  • 5) Number of people at the party
  • nbPersonnes = int(input())
    nbMax = 0
    nbActuel = 0
    for loop in range(nbPersonnes * 2):
       numero = int(input())
       if numero > 0:
          nbActuel = nbActuel + 1
       else:
          nbActuel = nbActuel - 1
       if nbActuel > nbMax:
          nbMax = nbActuel
    print(nbMax)
    
  • 6) Fire stations
  • nbPaires = int(input())
    for loop in range(nbPaires):
       xMin1 = int(input())
       xMax1 = int(input())
       yMin1 = int(input())
       yMax1 = int(input())
       xMin2 = int(input())
       xMax2 = int(input())
       yMin2 = int(input())
       yMax2 = int(input())
       if ( (xMax2 <= xMin1) or (xMax1 <= xMin2) ) or ( (yMax2 <= yMin1) or (yMax1 <= yMin2) ):
          print("NON")
       else:
          print("OUI")
    
  • 7) Missing person
  • numeroPersonne = int(input())
    tailleListe = int(input())
    estSorti  = False
    for loop in range(tailleListe):
       numero = int(input())
       if numero == numeroPersonne:
          estSorti = True
    if estSorti:
       print("Sorti de la ville")
    else:
       print("Encore dans la ville")
    
  • 8) The Big Party
  • espionDebut = int(input())
    espionFin = int(input())
    nbInvites = int(input())
    nbSuspects = 0
    for loop in range(nbInvites):
       debut = int(input())
       fin = int(input())
       if not( (espionFin < debut) or (fin < espionDebut) ):
          nbSuspects = nbSuspects + 1
    print(nbSuspects)
    
  • 9) The spy is unmasked!
  • 
    
  • 10) Color areas
  • 
    

  • 1) Department of Medicine: control of an epidemic
  • x = int(input())
    malade = 1
    jour = 1
    
    while malade < x:
       malade = malade * 3
       jour += 1
       
    print(jour)
    
  • 2) Administration: annual accounts
  • somme = 0
    T = True
    
    while T:
       x = int(input())
       if x == -1:
          T = False
       else:
          somme = somme + x
    print(somme)
    
  • 3) Department of Pedagogy: "it's more, it's less"
  • nbessai = 0
    nbtrouve = int(input())
    nbjoueur = None
                   
    while nbjoueur != nbtrouve:
        nbjoueur = int(input())
        nbessai += 1
        if nbjoueur < nbtrouve:
            print("c'est plus")
        elif nbjoueur > nbtrouve:
            print("c'est moins")
    
    print("Nombre d'essais nécessaires :")
    print(nbessai)
    
  • 4) Department of Architecture: construction of a pyramid
  • nbmaxpierres = int(input())
    
    hauteur = 0
    nbpierres = 0
    
    while nbpierres + (hauteur + 1) ** 2 <= nbmaxpierres:
        hauteur += 1
        nbpierres += hauteur ** 2
        
    print(hauteur)
    print(nbpierres)
    
  • 5) Department of chemistry: explosive mixture
  • nbtotomesure = int(input())
    temperatuemin = int(input())
    maxautorise = int(input())
    i = 0
    
    while i < nbtotomesure:
        temp = int(input())
        if temp < temperatuemin or temp > maxautorise:
            print("Alerte !!")
            break
        else:
            print("Rien à signaler")
        i += 1
    

Well done you have finished level 1 !! Level 2

BY SEBASTIEN XIA