Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct color{
    string name;
    int r,g,b;
};

int xx(int a){ return a * a; }

string colorName(struct color c[8], int r, int g, int b){
    int near = 99999;
    string name;
    rep(i,8){
        int dis = sqrt(xx(r - c[i].r) + xx(g - c[i].g) + xx(b - c[i].b));
        if(near > dis){
            near = dis;
            name = c[i].name;
        }
    }
    return name;
}

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

int DecimalNumber(char c16[2]){
    int c10 = 0;
    rep(i,chenge(c16[0])){
        c10 += 16;
    }
    c10+=chenge(c16[1]);
    
    return c10;
}


int main(){
    struct color c[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}
    };

    char r[2],g[2],b[2],gar;
    while(true){
        int R,G,B;
        cin >> gar;
        if(gar == '0') break;
        rep(i,2) cin >> r[i]; 
        rep(i,2) cin >> g[i]; 
        rep(i,2) cin >> b[i]; 

        R =  DecimalNumber(r);
        G =  DecimalNumber(g);
        B =  DecimalNumber(b);
        cout << colorName(c,R,G,B) << endl;
    }

}

C++: #include <iostream>
#include <math.h>
using namespace std;

int main() {
    double s,m;
    char a[8],c[8][8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"},h[17]="0123456789abcdef";
    int d[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}},
        w[6],i,j,e,r,g,b;
    while(cin >> a) {
		if (a[0]=='0') break;
		for (i=0;i<6;i++)  for (j=0;j<16;j++) if (a[i+1]==h[j]) w[i]=j;
		s=99999999; r=w[0]*16+w[1]; g=w[2]*16+w[3]; b=w[4]*16+w[5]; 
		for (i=0;i<8;i++) {
		 m=sqrt((r-d[i][0])*(r-d[i][0])+(g-d[i][1])*(g-d[i][1])+(b-d[i][2])*(b-d[i][2]));
		 if (m<s) { s=m; e=i;};
	 }
	 cout << c[e] << endl;
 }	
 return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define mod 1000000007
typedef long long ll;
using namespace std;
int d[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 ans[8]={
  "black",
  "blue",
  "lime",
  "aqua",
  "red",
  "fuchsia",
  "yellow",
  "white"
};
int F(char z){
  if('0'<=z&&z<='9')return z-'0';
  return 10+z-'a';
}
int main(){
  string s;
  while(cin>>s&&s!="0"){
    int a=F(s[1])*16+F(s[2]);
    int b=F(s[3])*16+F(s[4]);
    int c=F(s[5])*16+F(s[6]);
    int mini=mod,pnt;
    for(int i=0;i<8;i++){
      int dis=(d[i][0]-a)*(d[i][0]-a);
      dis+=(d[i][1]-b)*(d[i][1]-b);
      dis+=(d[i][2]-c)*(d[i][2]-c);
      if(dis<mini)mini=dis,pnt=i;
    }
    cout<<ans[pnt]<<endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int FF = 255, F  = 16;

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
int R[] = { 0, 0, 0, 0, FF, FF, FF, FF};
int G[] = { 0, 0, FF, FF, 0, 0, FF, FF};
int B[] = { 0, FF, 0, FF, 0, FF, 0, FF};

int num(char t)
{
    if(t >='0' && t <= '9') return t - '0';
    else return t - 'a' + 10;
}
int f(int n) { return n * n;}

int main()
{
    string s;
    while(cin >> s)
    {
        if(s == "0") break;

        int mind = FF * FF * F, d = 0, ans = 0;
        REP(8)
        {
            d = f(R[i] -( num(s[1]) * F + num(s[2]) )) + f(G[i]-(num(s[3])*F + num(s[4]))) + f(B[i] - (num(s[5])*F + num(s[6])));
            if(mind > d) { ans = i; mind = d;}
        }
        cout << name[ans] << endl;
    }
    return 0;
}

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

#define INF (1<<29)

string str;
const string color[8] = {"black","blue","lime","aqua","red","fuchsia",
			 "yellow","white"};
const string strong[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000",
			  "#ff00ff","#ffff00","#ffffff"};
 
int change(char ch)
{
    if ('0' <= ch && ch <= '9') {
	return ch - '0';
    }
    return 10 + (ch - 'a');
}
 
int d(string str1, string str2)
{
    int R1 = change(str1[1])*16 + change(str1[2]);
    int G1 = change(str1[3])*16 + change(str1[4]);
    int B1 = change(str1[5])*16 + change(str1[6]);
 
    int R2 = change(str2[1])*16 + change(str2[2]);
    int G2 = change(str2[3])*16 + change(str2[4]);
    int B2 = change(str2[5])*16 + change(str2[6]);
 
    int res = pow(R1-R2,2.0) + pow(G1-G2,2.0) + pow(B1-B2,2.0);
 
    return res;
}
 
int main()
{
    while (cin >> str, str != "0") {
	int min_ = INF,ans;
	for (int i = 0; i < 8; i++) {
	    int dist = d(str, strong[i]);
	    if (dist < min_) {
		min_ = dist;
		ans = i;
	    }
	}
	cout << color[ans] << endl;
    }
    return 0;
}