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 <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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

int main()
{
	int color[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 name[8]={
		"black",
		"blue",
		"lime",
		"aqua",
		"red",
		"fuchsia",
		"yellow",
		"white"
	};
	
	for(string s;cin>>s,s[0]!='0';){
		s=s.substr(1);
		int c[3];
		rep(i,3)
			c[i]=htoi(s[i*2])*16+htoi(s[i*2+1]);
		
		int res=0;
		rep(i,8){
			int ci=(c[0]-color[i][0])*(c[0]-color[i][0])+(c[1]-color[i][1])*(c[1]-color[i][1])+(c[2]-color[i][2])*(c[2]-color[i][2]);
			int cr=(c[0]-color[res][0])*(c[0]-color[res][0])+(c[1]-color[res][1])*(c[1]-color[res][1])+(c[2]-color[res][2])*(c[2]-color[res][2]);
			if(cr>ci)
				res=i;
		}
		cout<<name[res]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
 
const int INF = 10000000;
 
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, 255 }, { 0, 255, 0 },
             { 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 },
             { 255, 255, 0 }, { 255, 255, 255 } };
 
  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=INF,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<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 value[200]={};
    for(int i=0;i<10;i++)value['0'+i]=i;
    for(int i=0;i<6;i++)value['a'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=value[str[1+2*i]]*16+value[str[2+2*i]];
        int ans[8]={};
        for(int i=0;i<8;i++)
            for(int j=0;j<3;j++)
                ans[i]+=pow(colornum[i][j]-num[j],2);
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

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

string color[8] = {
	"black","blue","lime","aqua","red","fuchsia","yellow","white"
};
int dr[8] = {0,0,0,0,255,255,255,255};
int dg[8] = {0,0,255,255,0,0,255,255};
int db[8] = {0,255,0,255,0,255,0,255};

int to_i(string s){
	int n=0;

	if( s[0] >= '0' && s[0] <= '9' ){
		n += (s[0]-'0')*16;
	}else{
		n += (s[0]-'a'+10)*16;
	}
	if( s[1] >= '0' && s[1] <= '9' ){
		n += s[1] - '0';
	}else{
		n += s[1] - 'a' + 10;
	}
	return n;
}

vector<int> to_RGB(string s){
	vector<int> c;
	c.push_back( to_i( s.substr(1,2) ) );
	c.push_back( to_i( s.substr(3,4) ) );
	c.push_back( to_i( s.substr(5,6) ) );
	return c;
}

int d(int r,int rk,int g,int gk,int b,int bk){
	return (r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk);
}

int main(){
	string s;
	while( cin >> s , s != "0" ){
		vector<int> c = to_RGB( s );
		int ans = 200000;

		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			ans = min( ans , dk );
		}
		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			if( dk == ans ){
				cout << color[i] << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    for(;;){
        string s;
        cin >> s;
        if(s == "0")
            return 0;

        int a[3] = {0};
        for(int i=0; i<6; ++i){
            a[i/2] *= 16;
            if('0' <= s[i+1] && s[i+1] <= '9')
                a[i/2] += s[i+1] - '0';
            else
                a[i/2] += s[i+1] - 'a' + 10;
        }

        int k;
        int minD = INT_MAX;
        for(int i=0; i<8; ++i){
            int d = 0;
            for(int j=0; j<3; ++j){
                if(i & (1<<(2-j)))
                    d += (255 - a[j]) * (255 - a[j]);
                else
                    d += a[j] * a[j];
            }
            if(d < minD){
                minD = d;
                k = i;
            }
        }

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