Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;

template<class T>
T sqr(T obj) {return obj * obj;}

struct color {
	string name;
	int R, G, B;

	color(string n, int r, int g, int b) {
		name = n;
		R = r;
		G = g;
		B = b;
	}
};

color color_list[] = {
	color("black", 0x00, 0x00, 0x00),
	color("blue", 0x00, 0x00, 0xff),
	color("lime", 0x00, 0xff, 0x00),
	color("aqua", 0x00, 0xff, 0xff),
	color("red", 0xff, 0x00, 0x00),
	color("fuchsia", 0xff, 0x00, 0xff),
	color("yellow", 0xff, 0xff, 0x00),
	color("white", 0xff, 0xff, 0xff),
};

int main() {
	string s;
	while(cin >> s) {
		if(s[0] == '0')
			break;

		int mind, indx;
		indx = 0;
		mind = 1e8;

		int a[3];
		for(int j = 0; j < 3; j++) {
			int tmp = 0;
			if('0' <= s[1 + 2 * j] && s[1 + 2 * j] <= '9')
				tmp += (s[1 + 2 * j] - '0') * 16;
			else
				tmp += (s[1 + 2 * j] - 'a' + 10) * 16;

			if('0' <= s[2 + 2 * j] && s[2 + 2 * j] <= '9')
				tmp += (s[2 + 2 * j] - '0');
			else
				tmp += (s[2 + 2 * j] - 'a' + 10);
			a[j] = tmp;
		}

		for(int i = 0; i < 8; i++) {
			int d = 0;

			d += sqr(color_list[i].R - a[0]);
			d += sqr(color_list[i].G - a[1]);
			d += sqr(color_list[i].B - a[2]);
			if(d < mind) {
				indx = i;
				mind = d;
			}
		}
		cout << color_list[indx].name << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

int main(){
  string s;
  int color[][3] = {
                    {0, 0, 0}, //black
                    {0, 0, 0xff}, //blue
                    {0, 0xff, 0}, //lime
                    {0, 0xff, 0xff}, //aqua
                    {0xff, 0, 0}, //red
                    {0xff, 0, 0xff}, //fuchsia
                    {0xff, 0xff, 0}, //yellow
                    {0xff, 0xff, 0xff} //white
  };
  string ans[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  while(std::cin >> s, s != "0"){
    double min_val = 1e9;
    int num = -1;
    for (int i = 0; i < 8; i++) {
      double val = 0;
      unsigned int tmp;
      string type;
      // type = "0x" + s.substr(1, 2);
      type = s.substr(1, 2);
      // std::cout << type << std::endl;
      // sscanf("0x" + s.substr(), "%x", tmp);
      sscanf(type.c_str(), "%x", &tmp);
      // std::cout << type << std::endl;
      val += (color[i][0] - tmp)*(color[i][0] - tmp);
      
      type = "0x" + s.substr(3, 2);
      sscanf(type.c_str(), "%x", &tmp);
      val += (color[i][1] - tmp)*(color[i][1] - tmp);
      
      type = "0x" + s.substr(5, 2);
      sscanf(type.c_str(), "%x", &tmp);
      val += (color[i][2] - tmp)*(color[i][2] - tmp);
      if(min_val > val){
        min_val = val;
        num = i;
      }
    }
    std::cout << ans[num] << std::endl;
  }
  return 0;
}