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;
using ll = long long;

inline ll digit(char c) {
    return '0' <= c && c <= '9' ? c - '0' : c - 'a' + 10;
}

int main() {

    vector<string> clr = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
    vector<vector<ll>> clrv = {
        {0, 0, 0},
        {0, 0, 0xff},
        {0, 0xff, 0},
        {0, 0xff, 0xff},
        {0xff, 0, 0},
        {0xff, 0, 0xff},
        {0xff, 0xff, 0},
        {0xff, 0xff, 0xff}
    };

    string cl;
    while (cin >> cl, cl != "0") {

        ll r = digit(cl[1]) * 16 + digit(cl[2]);
        ll g = digit(cl[3]) * 16 + digit(cl[4]);
        ll b = digit(cl[5]) * 16 + digit(cl[6]);

        ll d2min = 0x7FFFFFFFFFFFFFFFLL, did = -1;
        for (ll i = 8; i--; ) {
            ll dr = clrv[i][0] - r;
            ll dg = clrv[i][1] - g;
            ll db = clrv[i][2] - b;
            ll d2 = dr*dr + dg*dg + db*db;
            if (d2min > d2) {
                d2min = d2;
                did = i;
            }
        }
        cout << clr[did] << "\n";
        
    }

}

C++: #include <iostream>

using namespace std;


int main(int argc, const char * argv[]) {
    
    while (true) {
        string input;
        cin >> input;
        if(input == "0"){
            break;
        }
        
/*        for(int i=1;i<7;i++){
            input[i] = toupper(input[i]);
        }
*/
        int red = stoi(input.substr(1,2), nullptr, 16);
        int green = stoi(input.substr(3,2), nullptr, 16);
        int blue = stoi(input.substr(5,2), nullptr, 16);
        
        
        red = (red < 128) ? 0 : 255;
        green = (green < 128) ? 0 : 255;
        blue = (blue < 128) ? 0 : 255;
        
        if(red == 0){
            if(green == 0){
                if(blue == 0){
                    cout << "black" << endl;
                }
                else{
                    cout << "blue" << endl;
                }
                
            }
            else{
                if(blue == 0){
                    cout << "lime" << endl;
                }
                else{
                    cout << "aqua" << endl;
                }
            }
        }
        else{
            if(green == 0){
                if(blue == 0){
                    cout << "red" << endl;
                }
                else{
                    cout << "fuchsia" << endl;
                }
                
            }
            else{
                if(blue == 0){
                    cout << "yellow" << endl;
                }
                else{
                    cout << "white" << endl;
                }
            }
        }
        
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int to10(const string &s) {
  int x = 0;
  for(int i = 0; i < s.size(); ++i) {
    int d;
    if(isdigit(s[i])) d = s[i] - '0';
    else d = 10 + s[i] - 'a';
    x = x * 16 + d;
  }
  return x;
}

vector<int> conv(const string &s) {
  vector<int> res(3);
  res[0] = to10(s.substr(1,2));
  res[1] = to10(s.substr(3,2));
  res[2] = to10(s.substr(5,2));
  return res;
}

int norm(vector<int> a, vector<int> b) {
  int res = 0;
  for(int i = 0; i < 3; ++i) {
    int sub = a[i] - b[i];
    res += sub * sub;
  }
  return res;
}


int main() {
  vector<string> name;
  vector<vector<int> > v;
  name.push_back("black");
  v.push_back(conv("#000000"));
  name.push_back("blue");
  v.push_back(conv("#0000ff"));
  name.push_back("lime");
  v.push_back(conv("#00ff00"));
  name.push_back("aqua");
  v.push_back(conv("#00ffff"));
  name.push_back("red");
  v.push_back(conv("#ff0000"));
  name.push_back("fuchsia");
  v.push_back(conv("#ff00ff"));
  name.push_back("yellow");
  v.push_back(conv("#ffff00"));
  name.push_back("white");
  v.push_back(conv("#ffffff"));
  string s;
  while(cin >> s && s != "0") {
    vector<int> x = conv(s);
    int k = 0;
    for(int i = 1; i < v.size(); ++i) {
      if(norm(x, v[i]) < norm(x, v[k])) {
        k = i;
      }
    }
    cout << name[k] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

int c(char ch) {
  if(isdigit(ch)) return ch-'0';
  return ch-'a'+10;
}

int d(string s) {
  return c(s[0])*16 + c(s[1]);
}

int main() {
  
  int colR[8];
  int colG[8];
  int colB[8];
  
  colR[0] = d("00"); colG[0] = d("00"); colB[0] = d("00");
  colR[1] = d("00"); colG[1] = d("00"); colB[1] = d("ff");
  colR[2] = d("00"); colG[2] = d("ff"); colB[2] = d("00");
  colR[3] = d("00"); colG[3] = d("ff"); colB[3] = d("ff");
  colR[4] = d("ff"); colG[4] = d("00"); colB[4] = d("00");
  colR[5] = d("ff"); colG[5] = d("00"); colB[5] = d("ff");
  colR[6] = d("ff"); colG[6] = d("ff"); colB[6] = d("00");
  colR[7] = d("ff"); colG[7] = d("ff"); colB[7] = d("ff");
  
  /*
  for(int i=0; i<8; i++) {
    colR[i] = i & 1 ? 255 : 0;
    colG[i] = i & 2 ? 255 : 0;
    colB[i] = i & 4 ? 255 : 0;
  }
  */
  
  string s;
  
  while(cin >> s) {
    if(s == "0") break;
    
    s = s.substr(1);
    
    int R = d(s.substr(0, 2));
    int G = d(s.substr(2, 2));
    int B = d(s.substr(4, 2));
    
    int minD = (int)1e9;
    int id = -1;
    for(int i=0; i<8; i++) {
      if( minD > pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0) ) {
	id = i;
	minD = pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0);
      }
    }
    
    cout << colors[id] << endl;
  }
  
  return 0;
}