본문 바로가기
알고리즘

[알고리즘] 2. 가장 낮은 절댓값 찾기

by 닉우 2020. 8. 12.

<문제주소>

 

https://www.codingame.com/ide/puzzle/temperatures


<문제>

 


<소스코드>

 

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

n = int(input())  # the number of temperatures to analyse

if n == 0:
    print("0")
else:
    result = 5527
    temperatures = input().split(' ')
    
    
    for i in range(n):
        t = int(temperatures[i])
        if t == 0:
            result = t
            break
        elif abs(t) < abs(result) :
            result = t
        elif abs(t) == abs(result):
            result = abs(t)


    print(result)

 

댓글