Skip to content

Instantly share code, notes, and snippets.

@ZengetsuFR
Created June 3, 2015 07:03
Show Gist options
  • Save ZengetsuFR/c2948649415bc6fb2d5c to your computer and use it in GitHub Desktop.
Save ZengetsuFR/c2948649415bc6fb2d5c to your computer and use it in GitHub Desktop.
Résolution du jeu "Températures" sur le site codingame.com
import sys, math
from bisect import bisect_left
from bisect import bisect_right
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
N = int(raw_input()) # the number of temperatures to analyse
TEMPS = raw_input() # the N temperatures expressed as integers ranging from -273 to 5526
positiv = False
if N==0:
print N
elif N>1:
#Créer une liste avec toutes les températures
#permet de récupérer rapidement toutes les températures pour
#pouvoir les trier par la suite
tempsList = TEMPS.split(" ")
tempsListofInt = []
for temps in tempsList:tempsListofInt.append(int(temps))
tempsListofInt.sort()
#bisect_right ou bisect_left nous permet de récuperer
#la valeur la plus proche de la valeur que nous passons en parametre
#pour notre cas c'est la valeur 0
try:
print tempsListofInt[bisect_right(tempsListofInt,0)]
except:
print tempsListofInt[bisect_left(tempsListofInt,0)-1]
else:
print TEMPS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment