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<cfloat>
#include<cmath>
using namespace std;

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int data[8][3] = { {0, 0, 0}   , 
                   {0, 0, 255} , 
                   {0, 255, 0} ,
                   {0, 255, 255} , 
                   {255, 0, 0} , 
                   {255, 0, 255} ,
                   {255, 255, 0} , 
                   {255, 255, 255}};

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}#include<iostream>
#include<cfloat>
#include<cmath>
using namespace std;

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int data[8][3] = { {0, 0, 0}   , 
                   {0, 0, 255} , 
                   {0, 255, 0} ,
                   {0, 255, 255} , 
                   {255, 0, 0} , 
                   {255, 0, 255} ,
                   {255, 255, 0} , 
                   {255, 255, 255}};

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
struct Color {char s[8]; int R, G, B; double d;};
Color t[8] = {{"black", 0, 0, 0}, {"blue", 0, 0, 255}, {"lime", 0, 255, 0}, {"aqua", 0, 255, 255}, {"red", 255, 0, 0}, {"fuchsia", 255, 0, 255}, {"yellow", 255, 255, 0}, {"white", 255, 255, 255}};
int main()
{
	char s[8];
	int R, G, B, i, r;
	double rd;
	while (scanf("%8s", s))
	{
		if (strcmp(s, "0") == 0) break;
		sscanf(s, "#%2x%2x%2x", &R, &G, &B);
		rd = 500.0;
		for (i = 0; i < 8; i++)
		{
			t[i].d = sqrt((double)(R - t[i].R)*(R - t[i].R) + (double)(G - t[i].G)*(G - t[i].G) + (double)(B - t[i].B)*(B - t[i].B));
			if (rd >= t[i].d)
				rd = t[i].d, r = i;
		}
		printf("%s\n", t[r].s);
	}
	return 0;
}

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

#define R 0
#define G 1
#define B 2

void print_col(int r, int g, int b)
{
  string col[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  int c[][3] = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255},
               {255, 0, 0}, {255, 0, 255}, {255, 255, 0}, {255, 255, 255}};
  double d = 1000000;
  double dd;
  int a = -1;

  for(int i = 0; i < 8; i++)
  {
    dd = pow(r - c[i][R], 2) + pow(g - c[i][G], 2) + pow(b - c[i][B], 2);
    if(dd < d)
    {
      d = dd;
      a = i;
    }
  }
  cout << col[a] << endl;
}

int to_num(char n)
{
  return n >= 'a' ? n - 'a' + 10 : n - '0';
}

int main()
{
  string s;
  int r, g, b;
  while(true)
  {
    cin >> s;
    if(s[0] == '0')
      break;
    r = to_num(s[1]) * 16 + to_num(s[2]);
    g = to_num(s[3]) * 16 + to_num(s[4]);
    b = to_num(s[5]) * 16 + to_num(s[6]);
    print_col(r, g, b);
  }
}

C++: #include <string>
#include <vector>
#include <iostream>

using namespace std;

int hextoi(string S)
{
    int sum = 0;
    
    if(isdigit(S[0]))
    {
        sum += (S[0] - 48) * 16;
    }
    else
    {
        sum += (S[0] - 87) * 16;
    }
    if(isdigit(S[1]))
    {
        sum += S[1] - 48;
    }
    else
    {
        sum += S[1] - 97;
    }
    
    return sum;
}

const vector<string> color = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

int main()
{
    string S;
    
    while(true)
    {
        cin >> S;
        
        if(S == "0") { break; }
        
        int R = hextoi(S.substr(1, 2));
        int G = hextoi(S.substr(3, 2));
        int B = hextoi(S.substr(5, 2));
        
        int near = 999999999, c = -1;
        
        for(int i = 0; i < 8; i++)
        {
            int R2 = ((i / 4) % 2 ? 255 : 0);
            int G2 = ((i / 2) % 2 ? 255 : 0);
            int B2 = ((i / 1) % 2 ? 255 : 0);
            
            int N2 = (R - R2) * (R - R2) + (B - B2) * (B - B2) + (G - G2) * (G - G2);
            
            if(N2 < near)
            {
                near = N2; c = i;
            }
        }
        
        cout << color[c] << endl;
    }
    
    return 0;
}

C++: #include<cstdlib>
char nm[][9]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int cl[][3]={{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};
char rgb[3][3];
int main(){
	while(scanf(" #%2s%2s%2s",rgb,rgb+1,rgb+2)==3){
		int mn=99999999,mi,d2,d;
		for(int i=0;i<8;i++){
			d2=0;
			for(int j=0;j<3;j++)d=cl[i][j]-strtol(rgb[j],NULL,16),d*=d,d2+=d;
			if(d2<mn)mn=d2,mi=i;
		}
		printf("%s\n",nm[mi]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<21

using namespace std;

int change(char c)
{
	if('a' <= c && c <= 'f') return int(c-'a') + 10;
	else return int(c-'0');
}

int main()
{
	string N[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

	int c[8][3] = {{0,0,0},{0,0,256},{0,256,0},{0,256,256},{256,0,0},{256,0,256},{256,256,0,},{256,256,256}};

	string s;
	while(cin >> s)
	{
		if(s == "0") break;
		
		int r = 0,g = 0,b = 0;

		r += change(s[1])*16 + change(s[2]);
		g += change(s[3])*16 + change(s[4]);
		b += change(s[5])*16 + change(s[6]);
		
		double ans = INF;
		rep(i,8)
		{
			double temp = sqrt(	(c[i][0]-r)*(c[i][0]-r) + (c[i][1]-g)*(c[i][1]-g) + (c[i][2]-b)*(c[i][2]-b));
			ans = min(ans,temp);
		}

		rep(i,8)
		{
			double temp = sqrt(	(c[i][0]-r)*(c[i][0]-r) + (c[i][1]-g)*(c[i][1]-g) + (c[i][2]-b)*(c[i][2]-b));
			if(temp == ans)
			{
				cout << N[i] << endl;
			}
		}
	}
	return 0;
}