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 <string>
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;
}

C++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

struct COLOR{
	string name;
	string R;
	string G;
	string B;
};

int hex2dec(string str){
	const char hex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
	return 16 * (int)lower_bound(hex,hex+16,str[0]) + (int)lower_bound(hex,hex+16,str[1]);
}

int main(){

	struct COLOR color[] = {
		"black","00","00","00",
		"blue","00","00","ff",
		"lime","00","ff","00",
		"aqua","00","ff","ff",
		"red","ff","00","00",
		"fuchsia","ff","00","ff",
		"yellow","ff","ff","00",
		"white","ff","ff","ff",
	};

	string str;
	while(cin >> str){
		if(str.size() == 1 && str[0] == '0') break;
		int r = hex2dec(str.substr(1,2));
		int g = hex2dec(str.substr(3,2));
		int b = hex2dec(str.substr(5,2));

		int dk = 10000000;
		int idx=0;
		for(int i=0;i<sizeof(color)/sizeof(struct COLOR); i++){
			int tmp;
			if(dk > (tmp=((r - hex2dec(color[i].R)) * (r - hex2dec(color[i].R))
				+ (g - hex2dec(color[i].G)) * (g - hex2dec(color[i].G))
				+ (b - hex2dec(color[i].B)) * (b - hex2dec(color[i].B))))){
					dk = tmp;
					idx=i;
			}
		}

		printf("%s\n",color[idx].name.c_str());
	}

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<21

using namespace std;

int change(char c)
{
	if('a' <= c && c <= 'f') return int(c-'a') + 10;
	else return int(c-'0');
}

int main()
{
	string N[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

	int c[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 s;
	while(cin >> s)
	{
		if(s == "0") break;
		
		int r = 0,g = 0,b = 0;

		r += change(s[1])*16 + change(s[2]);
		g += change(s[3])*16 + change(s[4]);
		b += change(s[5])*16 + change(s[6]);
		
		double ans = INF;
		rep(i,8)
		{
			double temp = 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));
			ans = min(ans,temp);
		}

		rep(i,8)
		{
			double temp = 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));
			if(temp == ans)
			{
				cout << N[i] << endl;
			}
		}
	}
	return 0;
}

C++: #include<string>
#include<cmath>
using namespace std;

#define R 0
#define G 1
#define B 2

void print_col(int r, int g, int b)
{
  string col[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  int c[][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}};
  double d = 1000000;
  double dd;
  int a = -1;

  for(int i = 0; i < 8; i++)
  {
    dd = pow(r - c[i][R], 2) + pow(g - c[i][G], 2) + pow(b - c[i][B], 2);
    if(dd < d)
    {
      d = dd;
      a = i;
    }
  }
  cout << col[a] << endl;
}

int to_num(char n)
{
  return n >= 'a' ? n - 'a' + 10 : n - '0';
}

int main()
{
  string s;
  int r, g, b;
  while(true)
  {
    cin >> s;
    if(s[0] == '0')
      break;
    r = to_num(s[1]) * 16 + to_num(s[2]);
    g = to_num(s[3]) * 16 + to_num(s[4]);
    b = to_num(s[5]) * 16 + to_num(s[6]);
    print_col(r, g, b);
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++)sixteen['a'-'0'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=(num[j]-colornum[i][j])*(num[j]-colornum[i][j]);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=0;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}