Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct color{
    string name;
    int r,g,b;
};

int xx(int a){ return a * a; }

string colorName(struct color c[8], double r, double g, double b){
    double near = 99999;
    string name;
    rep(i,8){
        double dis = sqrt(xx(r - c[i].r) + xx(g - c[i].g) + xx(b - c[i].b));
        if(near > dis){
            near = dis;
            name = c[i].name;
        }
    }
    return name;
}

int chenge(char a){
    if(a >= '0' && a <= '9') return a - '0';
    else return a - 'a' + 10;
}

int DecimalNumber(char c16[2]){
    int c10 = 0;
    rep(i,chenge(c16[0])){
        c10 += 16;
    }
    c10+=chenge(c16[1]);
    
    return c10;
}


int main(){
    struct color c[8] = {
        {"black", 0, 0, 0},
        {"blue", 0, 0, 255},
        {"lime", 0, 255, 0},
        {"aqua", 0, 255, 255},
        {"red", 255, 0, 0},
        {"fuchsia", 255, 0, 255},
        {"yellow", 255, 255, 0},
        {"white", 255, 255, 255}
    };

    char r[2],g[2],b[2],gar;
    while(true){
        int R,G,B;
        cin >> gar;
        if(gar == '0') break;
        rep(i,2) cin >> r[i]; 
        rep(i,2) cin >> g[i]; 
        rep(i,2) cin >> b[i]; 

        R =  DecimalNumber(r);
        G =  DecimalNumber(g);
        B =  DecimalNumber(b);
        cout << colorName(c,static_cast<int>(R),static_cast<int>(G),static_cast<int>(B)) << endl;
    }

}

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

char l[6];
string s;

string color() {
	for (int i = 0; i < 6; i++) {
		l[i] = s[i + 1];
	}
	int r, g, b;
	int z[6];

	for (int i = 0; i < 6; i++) {
		if (l[i] == '0') {
			z[i] = 0;
		}
		else if (l[i] == '1') {
			z[i] = 1;
		}
		else if (l[i] == '2') {
			z[i] = 2;
		}
		else if (l[i] == '3') {
			z[i] = 3;
		}
		else if (l[i] == '4') {
			z[i] = 4;
		}
		else if (l[i] == '5') {
			z[i] = 5;
		}
		else if (l[i] == '6') {
			z[i] = 6;
		}
		else if (l[i] == '7') {
			z[i] = 7;
		}
		else if (l[i] == '8') {
			z[i] = 8;
		}
		else if (l[i] == '9') {
			z[i] = 9;
		}
		else if (l[i] == 'a') {
			z[i] = 10;
		}
		else if (l[i] == 'b') {
			z[i] = 11;
		}
		else if (l[i] == 'c') {
			z[i] = 12;
		}
		else if (l[i] == 'd') {
			z[i] = 13;
		}
		else if (l[i] == 'e') {
			z[i] = 14;
		}
		else if (l[i] == 'f') {
			z[i] = 15;
		}
	}

	r = z[0] * 16 + z[1];
	g = z[2] * 16 + z[3];
	b = z[4] * 16 + z[5];

	//ff == 255;
	if (r <= 128) {
		//black,blue,lime,aqua
		if (g <= 128) {
			//black,blue
			if (b <= 128) {
				return "black";
			}
			else {
				return "blue";
			}
		}
		else {
			//lime,aqua
			if (b <= 128) {
				return "lime";
			}
			else {
				return "aqua";
			}
		}
	}
	else {
		//red,fuchsia,yellow,white
		if (g <= 128) {
			//red,fu
			if (b <= 128) {
				return "red";
			}
			else {
				return "fuchsia";
			}
		}
		else {
			if (b <= 128) {
				return "yellow";
			}
			else
			{
				return "white";
			}
		}
	}
}

int main() {
	string g[100];
	int x;
	for (int i = 0;; i++){
		cin >> s;
		if (s == "0") {
			x = i;
			break;
		}
		g[i] = color();
	}
	for (int i = 0; i < x; i++){
		cout << g[i] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2100000000
using namespace std;
int main(void)
{
	char color[8][15]={"black","blue","lime","aqua",
				  "red","fuchsia","yellow","white"};
	int i,j,k,a,b,c,mini;
	int suu[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	int red[8]={0,0,0,0,255,255,255,255},
		lime[8]={0,0,255,255,0,0,255,255},
		blue[8]={0,255,0,255,0,255,0,255};
	char sin[17]={"0123456789abcdef"};
	char pu[8];
	while(1) {
		cin>>pu;
		if(pu[0]=='0') break;
		a=b=c=0;
		for(i=1;i<8;i++) {
			for(j=0;j<16;j++) {
				if(pu[i]==sin[j]) {
					if(i<=2) {
						if(i%2==1)a+=suu[j]*16;
						else a+=suu[j];
					}
					else if(i<=4) {
						if(i%2==1) b+=suu[j]*16;
						else b+=suu[j];
					}
					else {
						if(i%2==1) c+=suu[j]*16;
						else c+=suu[j];
					}
					break;
				}
			}
		}
		mini=INF;
		int d,x;
		for(i=0;i<8;i++) {
			d=sqrt(((a-red[i])*(a-red[i]))+
					((b-lime[i])*(b-lime[i]))+
					((c-blue[i])*(c-blue[i])));
			if(mini>d) {
				mini=d;
				x=i;
			}
		}
		cout<<color[x]<<endl;
	}
}

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

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

int main() {

  string s;

  int coltabel[8][3] = { { 0, 0, 0 }, { 0, 0, 256 }, { 0, 256, 0 },
			 { 0, 256, 256 }, { 256, 0, 0 }, { 256, 0, 256 },
			 { 256, 256, 0 }, { 256, 256, 256 } };

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

  while(true) {

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

    int r,g,b;
    r = base16(s[1])*16+base16(s[2]);
    g = base16(s[3])*16+base16(s[4]);
    b = base16(s[5])*16+base16(s[6]);

    int res,tmp=256*256*3,t;

    for(int i=0; i<8; i++) {
      if( ( t = (r-coltabel[i][0])*(r-coltabel[i][0])
	  + (g-coltabel[i][1])*(g-coltabel[i][1])
	  + (b-coltabel[i][2])*(b-coltabel[i][2]) )
	  < tmp ) {
	//cout<<t<<" "<<i<<endl;
	res = i;
	tmp = t;
      }
    }

    cout<<nametable[res]<<endl;
  }
}

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

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int 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"};

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}