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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  char str[8][10]={"black","blue","lime","aqua",
		   "red","fuchsia","yellow","white"};
  int col[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}};
  while(1){
    string s;
    cin>>s;
    if(s=="0")break;
    vi v(3,0);
    rep(i,3){
      if('a'<=s[i*2+1] && s[i*2+1]<='f')v[i]+=10+(s[i*2+1]-'a');
      else v[i]+=s[i*2+1]-'0';
      v[i]*=16;
      if('a'<=s[i*2+2] && s[i*2+2]<='f')v[i]+=10+(s[i*2+2]-'a');
      else v[i]+=s[i*2+2]-'0';
    }
    int ans=INF;
    rep(i,8){
      int tmp=0;
      rep(j,3)tmp+=(col[i][j]-v[j])*(col[i][j]-v[j]);
      ans=min(ans,tmp);
    }
    rep(i,8){
      int tmp=0;
      rep(j,3)tmp+=(col[i][j]-v[j])*(col[i][j]-v[j]);
      if(tmp==ans){
	cout<<str[i]<<endl;
	break;
      }
    }

  }
}

C++: #include<iostream>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=(s[1]-'0')*16+(s[2]-'0');
  int green=(s[3]-'0')*16+(s[4]-'0');
  int blue=(s[5]-'0')*16+(s[6]-'0');
  return sqrt(pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2));
}

int cl[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(){
  string s;
  while(cin>>s,s!="0"){
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(s,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(s,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

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

const int RGB[][ 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 xtod( char* c )
{
	int ret = 0;
	int mag = 16;
	for( int i = 0; i < 2; ++i, ++c ){
		int d = 0;
		if( *c >= '0' && *c <= '9' ){
			d = *c - '0';
		}else{
			d = *c - 'a' + 10;
		}
		ret += ( d * mag );
		mag /= 16;
	}
	return ret;
}

int distance( const int* o, int* x )
{
	int dd[ 3 ];
	for( int i = 0; i < 3; ++i ){
		dd[ i ] = x[ i ] - o[ i ];
		dd[ i ] *= dd[ i ];
	}
	return dd[ 0 ] + dd[ 1 ] + dd[ 2 ];
}

int main()
{
	char col[ 8 ];

	while( cin >> col && *col != '0' ){
		int n[ 3 ];
		for( int i = 0; i < 3; ++i ){
			n[ i ] = xtod( col + ( 1 + i * 2 ) );
		}
		int d[ 8 ];
		for( int i = 0; i < 8; ++i ){
			d[ i ] = distance( RGB[ i ], n );
		}
		int ans = 0;
		int ansD = 200000;
		for( int i = 0; i < 8; ++i ){
			if( d[ i ] < ansD ){
				ans = i;
				ansD = d[ i ];
			}
		}
		cout << color[ ans ] << endl;
	}

	return 0;
}

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

int six_ten(char x){
	if(x >= '0' && x <= '9'){
		return x - '0';
	}
	else{
		return 10 + (x - 'a');
	}
}
 
int main(){
    int color_data[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 color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	string s;
	while(true){
		cin >> s;
		if(s == "0")break;
		int r,g,b;
		r = 16 * six_ten(s[1]) + six_ten(s[2]);
		g = 16 * six_ten(s[3]) + six_ten(s[4]);
		b = 16 * six_ten(s[5]) + six_ten(s[6]);

		double maxi = DBL_MAX;
		int key;
		for(int i = 0; i < 8; i++){
			double R = r - color_data[i][0];
			double G = g - color_data[i][1];
			double B = b - color_data[i][2];
			R *= R;
			G *= G;
			B *= B;
			double RGB = sqrt(R + G + B);
			if(RGB < maxi){
				maxi = RGB;
				key = i;
			}
		}
		cout << color[key] << endl;
	}
    return 0;
}

C++: #include <iostream>
using namespace std;


int main(int argc, const char * argv[]) {
    
    while (true) {
        string input;
        cin >> input;
        if(input == "0"){
            break;
        }

        int red = stoi(input.substr(1,2), NULL, 16);
        int green = stoi(input.substr(3,2), NULL, 16);
        int blue = stoi(input.substr(5,2), NULL, 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;
}