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

class Col
{
public:
  int R,G,B;
  Col():R(0),G(0),B(0){}
  Col(int R,int G,int B):R(R),G(G),B(B){}
};

int _16to10(string s)
{
  int a[2];
  for(int i=0;i<2;i++)
    {
      if(s[i] == 'a')
	a[i] = 10;
      else if(s[i] == 'b')
	a[i] = 11;
      else if(s[i] == 'c')
	a[i] = 12;
      else if(s[i] == 'd')
	a[i] = 13;
      else if(s[i] == 'e')
	a[i] = 14;
      else if(s[i] == 'f')
	a[i] = 15;
      else 
	a[i] = s[i] - '0';
    }
  return a[1]+a[0]*16;
}

int main()
{
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8),name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0,0,0);
  vec[1] = Col(0,0,ff);
  vec[2] = Col(0,ff,0);
  vec[3] = Col(0,ff,ff);
  vec[4] = Col(ff,0,0);
  vec[5] = Col(ff,0,ff);
  vec[6] = Col(ff,ff,0);
  vec[7] = Col(ff,ff,ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while(true)
    {
      cin >> s;
      if(s == "0")
	break;
      int R,G,B;
      R = _16to10(s.substr(1,2));
      G = _16to10(s.substr(3,2));
      B = _16to10(s.substr(5,2));

      double men = (1<<28),pos = -1;
      for(int i=0;i<8;i++)
	{
	  double d =  sqrt(pow(R-vec[i].R,2)+pow(B-vec[i].B,2)+pow(G-vec[i].G,2));
	  if(men > d)
	    {
	      men = d;
	      pos = i;
	    }
	}
      cout << name[pos] << endl;

    }
  return 0;
}

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

using namespace std;
struct color
{
	string str;
	int RGB[3];
};

void solve()
{
	color Color[8];
	Color[0].str = "black";
	Color[0].RGB[0] = 0;	Color[0].RGB[1] = 0;	Color[0].RGB[2] = 0;
	Color[1].str = "blue";
	Color[1].RGB[0] = 0;	Color[1].RGB[1] = 0;	Color[1].RGB[2] = 255;
	Color[2].str = "lime";
	Color[2].RGB[0] = 0;	Color[2].RGB[1] = 255;	Color[2].RGB[2] = 0;
	Color[3].str = "aqua";
	Color[3].RGB[0] = 0;	Color[3].RGB[1] = 255;	Color[3].RGB[2] = 255;
	Color[4].str = "red";
	Color[4].RGB[0] = 255;	Color[4].RGB[1] = 0;	Color[4].RGB[2] = 0;
	Color[5].str = "fuchsia";
	Color[5].RGB[0] = 255;	Color[5].RGB[1] = 0;	Color[5].RGB[2] = 255;
	Color[6].str = "yellow";
	Color[6].RGB[0] = 255;	Color[6].RGB[1] = 255;	Color[6].RGB[2] = 0;
	Color[7].str = "white";
	Color[7].RGB[0] = 255;	Color[7].RGB[1] = 255;	Color[7].RGB[2] = 255;

	string str;
	while(cin >> str, str[0] != '0')
	{
		int C[3] = {0};
		for(int i = 0; i < 3; ++i)
		{
			if('a' <= str[2 * i + 1] && str[2 * i + 1] <= 'f')
			{
				C[i] += (str[2 * i + 1] - 'a' + 10) * 16;
			}
			else if('0' <= str[2 * i + 1] && str[2 * i + 1] <= '9')
			{
				C[i] += (str[2 * i + 1] - '0') * 16;
			}
		}
		for(int i = 1; i < 4; ++i)
		{
			if('a' <= str[2 * i] && str[2 * i] <= 'f')
			{
				C[i - 1] += str[2 * i] - 'a' + 10;
			}
			else if('0' <= str[2 * i] && str[2 * i] <= '9')
			{
				C[i - 1] += str[2 * i] - '0';
			}
		}
		int index = 0;
		int dist = 0;
		int min = 999999999;
		for(int i = 0; i < 8; ++i)
		{
			dist = (C[0] - Color[i].RGB[0]) * (C[0] - Color[i].RGB[0])
				 + (C[1] - Color[i].RGB[1]) * (C[1] - Color[i].RGB[1])
				 + (C[2] - Color[i].RGB[2]) * (C[2] - Color[i].RGB[2]);
			if(dist < min)
			{
				min = dist;
				index = i;
			}
		}
		cout << Color[index].str << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	map <char, int>b;
	b.insert(map<char, int>::value_type('0', 0));
	b.insert(map<char, int>::value_type('1', 1));
	b.insert(map<char, int>::value_type('2', 2));
	b.insert(map<char, int>::value_type('3', 3));
	b.insert(map<char, int>::value_type('4', 4));
	b.insert(map<char, int>::value_type('5', 5));
	b.insert(map<char, int>::value_type('6', 6));
	b.insert(map<char, int>::value_type('7', 7));
	b.insert(map<char, int>::value_type('8', 8));
	b.insert(map<char, int>::value_type('9', 9));
	b.insert(map<char, int>::value_type('a', 10));
	b.insert(map<char, int>::value_type('b', 11));
	b.insert(map<char, int>::value_type('c', 12));
	b.insert(map<char, int>::value_type('d', 13));
	b.insert(map<char, int>::value_type('e', 14));
	b.insert(map<char, int>::value_type('f', 15));
	string d[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int e[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 a;
	while (cin >> a&&a != "0") {
		int sa = 10000, t[3];
		string iro;
		for (int i = 1; i < 7; i += 2) {
			char f = a[i], g = a[i + 1];
			t[(i - 1) / 2] = b[f]*16 + b[g];
		}
		for (int i = 7; i >= 0; i--) {
			int h = sqrt(pow((e[i][0] - t[0]), 2) + pow((e[i][1] - t[1]), 2) + pow((e[i][2] - t[2]), 2));
			if (h <= sa) {
				sa = h;
				iro = d[i];
			}
		}
		cout << iro << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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}};
    int sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++)sixteen['a'-'0'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=(num[j]-colornum[i][j])*(num[j]-colornum[i][j]);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}