Created
June 3, 2015 07:03
-
-
Save ZengetsuFR/c2948649415bc6fb2d5c to your computer and use it in GitHub Desktop.
Résolution du jeu "Températures" sur le site codingame.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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