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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
unsigned int hexToUInt(const std::string &str)
{
  unsigned int val = 0;
  unsigned int v;
  for(size_t ix = 0; ix != str.size(); ++ix) {
    char ch = str[ix];
    if( ch >= '0' && ch <= '9' )
      v = ch - '0';
    else if( ch >= 'A' && ch <= 'F' )
      v = ch - 'A' + 10;
    else if( ch >= 'a' && ch <= 'f' )
      v = ch - 'a' + 10;
    else
      continue;    // 16?????°????????§???????????´???
    val = val * 16 + v;
  }
  return val;
}
void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

const string li[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000","#ff00ff","#ffff00","#ffffff"};
const string name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int cola[3],colb[8][3];
  rep(k,8){
    string str = "";
    REP(i,1,li[k].size()){
      if(i % 2){
        str += li[k][i];
      }
      else{
        str += li[k][i];
        colb[k][i/2-1] = hexToUInt(str);
        str.clear();
      }
    }
  }
  while(cin >> s && s != "0"){
    string str="";
    REP(i,1,s.size()){
      if(i % 2){
        str += s[i];
      }
      else{
        str += s[i];
        cola[i/2-1] = hexToUInt(str) ;
        str.clear();
      }
    }
    int mi = inf;
    int suf = 0;
    rep(i,8){
      int d = pow((cola[0] - colb[i][0]),2) + pow((cola[1] - colb[i][1]),2)+pow((cola[2] - colb[i][2]),2);
      if(mi > d){
        suf = i;
        mi = d;
      }
    }
    cout << name[suf]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cmath>

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[][4] = {{{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 name[9] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int table[][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}
  };

  const char *name[] = {
    "black",
    "blue",
    "lime",
    "aqua",
    "red",
    "fuchsia",
    "yellow",
    "white",
  };

  const int n = sizeof(table) / sizeof(table[0]);

  char buff[256];
  while(fgets(buff,sizeof(buff),stdin), buff[0] != '0'){
    char col[3] = { 0 };
    int rgb[3];
    int diff = INT_MAX;
    int ans;
    REP(i,3){
      col[0] = buff[1 + i*2];
      col[1] = buff[1 + i*2 + 1];

      sscanf(col, "%x", rgb + i);
    }

#define DBL(x) ((x)*(x))
    REP(i,n){
      int tmp = 0;
      REP(j,3)
        tmp += DBL(rgb[j] - table[i][j]);
      if(tmp < diff){
        diff = tmp;
        ans = i;
      }
    }
    puts(name[ans]);
  }

  return 0;
}