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

class Color
{
public:
  Color(int r, int g, int b);
  int get_R();
  int get_G();
  int get_B();
  string near_color();

private:
  int m_R;
  int m_G;
  int m_B;
  double diff( Color col );

  static Color black;
  static Color blue;
  static Color lime;
  static Color aqua;
  static Color red;
  static Color fuchsia;
  static Color yellow;
  static Color white;
};

Color Color::black(   0x00, 0x00, 0x00 );
Color Color::blue(    0x00, 0x00, 0xff );
Color Color::lime(    0x00, 0xff, 0x00 );
Color Color::aqua(    0x00, 0xff, 0xff );
Color Color::red(     0xff, 0x00, 0x00 );
Color Color::fuchsia( 0xff, 0x00, 0xff );
Color Color::yellow(  0xff, 0xff, 0x00 );
Color Color::white(   0xff, 0xff, 0xff );

Color::Color(int r, int g, int b)
{
  m_R = r;
  m_G = g;
  m_B = b;
}

int Color::get_R()
{
  return m_R;
}

int Color::get_G()
{
  return m_G;
}

int Color::get_B()
{
  return m_B;
}

double Color::diff( Color col )
{
  return sqrt( pow(m_R - col.get_R(), 2) + pow(m_G - col.get_G(), 2) + pow(m_B - col.get_B(), 2) );
}

string Color::near_color()
{
  struct Color_name
  {
    string name;
    Color color;
  };
  Color_name colors[8] = {
    "black", black,
    "blue", blue,
    "lime", lime,
    "aqua", aqua,
    "red", red,
    "fuchsia", fuchsia,
    "yellow", yellow,
    "white", white,
  };
  Color_name min = colors[0];
  for (int i=1; i<8; i++)
  {
    if ( diff(colors[i].color) < diff(min.color) )
    {
      min = colors[i];
    }
  }
  return min.name;
}

int main()
{
  while(true)
  {
    string color;
    getline(cin, color);
    if ( color == "0" ) return 0;

    int r = stoi( color.substr(1, 2), 0, 16 );
    int g = stoi( color.substr(3, 2), 0, 16 );
    int b = stoi( color.substr(5, 2), 0, 16 );
    Color c(r, g, b);
    cout << c.near_color() << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  int n;
  string name;
};

const int c[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff}, {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};

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

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = sqrt((c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b));
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}

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

using namespace std;

int main(){

	string inp;
	string base = ("0123456789abcdef" );
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[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 r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0);
		for (int i = 1; i < 8; i++){
			if (ansnum>pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0)){
				ans = i;
				ansnum = pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0);
			}
		}

		cout << scol[ans] << endl;

	}
}

C++: //何を何に変換するかが大事だと思う。(良問)
#include<stdio.h>
#define INF 100000000

char *color[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int X[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 main(){
	char c[3];
	int rgb[3];
	int index;
	int mini;
	
	while( scanf("%c",c) ){
		if( c[0] == '\n' || c[0] == '\r' )
			continue;			
		if( c[0] == '0' )
			break;
			
		for( int i = 0;i < 3;i++ ){
			int num = 0;
			scanf("%c%c",c,c+1);
			if( c[0] <= '9' )
				num += (c[0]-'0')*16;
			else
				num += (c[0]-'a'+10)*16;
			if( c[1] <= '9' )
				num += (c[1]-'0');
			else
				num += (c[1]-'a'+10);
			rgb[i] = num;
		}
		
		mini = INF;
		
		for( int i = 0;i < 8;i++ ){
			int num = 0;
			for( int j = 0;j < 3;j++ ){
				num += (X[i][j]-rgb[j])*(X[i][j]-rgb[j]);
			}
			if( mini > num ){
				index = i;
				mini = num;
			}
		}
		printf("%s\n",color[index]);
	}
	return 0;
}