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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
map<char,int> ma;
void mainmain(){
	rep(i,10){
		ma[(char)(i+'0')]=i;
	}
	char a[]={'a','b','c','d','e','f'};
	rep(i,6){
		ma[a[i]]=i+10;
	}
	string s;
	int r[]={0,0,0,0,1,1,1,1};
	int g[]={0,0,1,1,0,0,1,1};
	int b[]={0,1,0,1,0,1,0,1};
	string ans[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while(cin>>s,s[0]!='0'){
		int rr=0,gg=0,bb=0;
		rr=ma[s[1]]*16+ma[s[2]];
		gg=ma[s[3]]*16+ma[s[4]];
		bb=ma[s[5]]*16+ma[s[6]];
		int c=-1;
		int d=INF;
		rep(i,8){
			int t=(rr-r[i]*256)*(rr-r[i]*256)+(gg-g[i]*256)*(gg-g[i]*256)+(bb-b[i]*256)*(bb-b[i]*256);
			if(t<d){
				d=t;
				c=i;
			}
		}
		cout<<ans[c]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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>
using namespace std;


int tmp[2] = {16,1};
string s[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int hoge[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 to_ten(string s){
  int ans=0;
  for(int i=0; i<2; i++){
    if(s[i] == 'a') ans += 10*tmp[i];
    else if(s[i] == 'b') ans += 11*tmp[i];
    else if(s[i] == 'c') ans += 12*tmp[i];
    else if(s[i] == 'd') ans += 13*tmp[i];
    else if(s[i] == 'e') ans += 14*tmp[i];
    else if(s[i] == 'f') ans += 15*tmp[i];
    else ans += stoi(s.substr(i,1))*tmp[i];
  }
  return ans;
}

double d(string r,string g,string b,int i){
  double ans = 0;
  ans += (to_ten(r) - hoge[i][0]) * (to_ten(r) - hoge[i][0]);
  ans += (to_ten(g) - hoge[i][1]) * (to_ten(g) - hoge[i][1]);
  ans += (to_ten(b) - hoge[i][2]) * (to_ten(b) - hoge[i][2]);
  return ans;
}

int main(){


  while(1){
    string in; cin >> in;
    if(in == "0") break;
    string r = in.substr(1,2);
    string g = in.substr(3,2);
    string b = in.substr(5,2);

    double min = (int)1e+308;
    int index=100;
    for(int i=0; i<8; i++){
      if(d(r,g,b,i) < min ){
	index = i;
	min = d(r,g,b,i);
      }
      //   cout  << d(r,g,b,i) << " ";
    }
    cout << s[index] << "\n";
  }


}