Created
January 21, 2014 22:42
-
-
Save miry/8549982 to your computer and use it in GitHub Desktop.
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
# Codingame: http://www.codingame.com/ide/?target=clogin&s=1&id=227787048586488d4709f87be22b41eab2321d#!test:247723:true:%2523!list | |
n = STDIN.gets.to_i | |
if n == 0 | |
puts 0 | |
exit | |
end | |
values = STDIN.gets.split(' ').map(&:to_i) | |
closest = values.shift | |
closest_distance = closest.abs | |
values.each do |value| | |
distance = value.abs | |
next if distance > closest_distance | |
if distance < closest_distance || value > closest | |
closest = value | |
closest_distance = closest.abs | |
end | |
end | |
puts closest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment