백준 10600번: Web Colors #Python

ColorlessDia·2025년 11월 13일

algorithm/baekjoon

목록 보기
725/808
import sys

def calc_distance(R, G, B, r, g, b):
    return (((R - r) ** 2) + ((G - g) ** 2) + ((B - b) ** 2)) ** 0.5

input = sys.stdin.readline

web_colors = {
    'White': (255, 255, 255),
    'Silver': (192, 192, 192),
    'Gray':	(128, 128, 128),
    'Black': (0, 0, 0),
    'Red': (255, 0, 0),
    'Maroon': (128, 0, 0),
    'Yellow': (255, 255, 0),
    'Olive': (128, 128, 0),
    'Lime':	(0, 255, 0),
    'Green': (0, 128, 0),
    'Aqua':	(0, 255, 255),
    'Teal':	(0, 128, 128),
    'Blue':	(0, 0, 255),
    'Navy':	(0, 0, 128),
    'Fuchsia': (255, 0, 255),
    'Purple': (128, 0, 128),
}

while True:
    r, g, b = map(int, input().split())

    if r == g == b == -1:
        break

    color_name = None
    minimum_distance = 1000

    for color, (R, G, B) in web_colors.items():
        distance = calc_distance(R, G, B, r, g, b)

        if distance < minimum_distance:
            color_name = color
            minimum_distance = distance
    
    print(color_name)

0개의 댓글