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 <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

map<string, int> hex_table;

void table_init() {
	hex_table.clear();
	string table = "0123456789abcdef";
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			hex_table[table.substr(i,1) + table.substr(j,1)] = i * 16 + j;
}

int hex2dec(string H) {
	return hex_table[H];
}

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string color_code[] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int color_value[8][3];

inline double POW(double v) {
	return v * v;
}

void color_value_init() {
	for(int i = 0; i < 8; i++) {
		string R = color_code[i].substr(0, 2);
		string G = color_code[i].substr(2, 2);
		string B = color_code[i].substr(4, 2);
		color_value[i][0] = hex2dec(R);
		color_value[i][1] = hex2dec(G);
		color_value[i][2] = hex2dec(B);
	}
}

int main() {
	table_init();
	color_value_init();
	for(string line; getline(cin, line), line != "0";) {
		int R = hex2dec(line.substr(1, 2));
		int G = hex2dec(line.substr(3, 2));
		int B = hex2dec(line.substr(5, 2));
#if 0
		debug(hex2dec(R));
		debug(hex2dec(G));
		debug(hex2dec(B));
#endif

		int idx = -1;
		double vmin = 1e10;
		for(int i = 0; i < 8; i++) {
			double v = sqrt(POW(R - color_value[i][0]) + POW(G - color_value[i][1]) + POW(B - color_value[i][2]));
			if(v < vmin) {
				idx = i;
				vmin = v;
			}
		}

		cout << name[idx] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define SQ(X) ((X)*(X))

typedef struct{
    char name[8];
    int r,g,b;
} Color;

double getDist2(Color col1, Color col2);
void GetCol(Color *cp, char *st);
int getHex(char c);

int main(){
    Color col[8];
    Color inCol;
    double dist2;
    int nearest, nearestId;
    char buf[16];
    
    // init color table
    col[0].r=0x00; col[0].g=0x00; col[0].b=0x00; strcpy(col[0].name, "black");
    col[1].r=0x00; col[1].g=0x00; col[1].b=0xff; strcpy(col[1].name, "blue");
    col[2].r=0x00; col[2].g=0xff; col[2].b=0x00; strcpy(col[2].name, "lime");
    col[3].r=0x00; col[3].g=0xff; col[3].b=0xff; strcpy(col[3].name, "aqua");
    col[4].r=0xff; col[4].g=0x00; col[4].b=0x00; strcpy(col[4].name, "red");
    col[5].r=0xff; col[5].g=0x00; col[5].b=0xff; strcpy(col[5].name, "fuchsia");
    col[6].r=0xff; col[6].g=0xff; col[6].b=0x00; strcpy(col[6].name, "yellow");
    col[7].r=0xff; col[7].g=0xff; col[7].b=0xff; strcpy(col[7].name, "white");
    
    while (scanf("%s",buf), buf[0]!='0'){
        GetCol(&inCol, buf);
        nearest = 65536*4;
        for (int i=0; i<8; i++){
            dist2 = getDist2(col[i], inCol);
            if (dist2 < nearest) nearest=dist2, nearestId=i;
        }
        printf("%s\n", col[nearestId].name);
    }    
    return 0;
}

double getDist2(Color col1, Color col2){
    return SQ(col1.r-col2.r)+SQ(col1.g-col2.g)+SQ(col1.b-col2.b);
}

void GetCol(Color *cp, char *st){
    cp->r = getHex(st[1])*0x10 + getHex(st[2]);
    cp->g = getHex(st[3])*0x10 + getHex(st[4]);
    cp->b = getHex(st[5])*0x10 + getHex(st[6]);
}

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

C++: #include<bits/stdc++.h>
#define INF 2100000000
using namespace std;
int main(void)
{
	int i,j,k,a,b,c,mini;
	char color[8][15]={"black","blue","lime","aqua",
				  "red","fuchsia","yellow","white"};
	int suu[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
		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=0;
		for(i=0;i<8;i++) {
			d=((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<string>
using namespace std;

int main(){
  string data;
  int f1,f2;

  while(1){
    getline(cin,data);
    if(data[0] == '0') return 0;
    f1 = f2 = 0
    for(int i = 0; i  < 10; i++){
      if(data[1] == i)
	f1 = 1;
      if(data[2] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
      data[1] = 0;
      data[2] = 0;
    }else{
      data[1] == f;
      data[2] == f;
    } 
    for(int i = 0; i  < 10; i++){
      if(data[3] == i)
	f1 = 1;
      if(data[4] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
      data[3] = 0;
      data[4] = 0;
    }else{
      data[3] == f;
      data[4] == f;
    } 
    for(int i = 0; i  < 10; i++){
      if(data[5] == i)
	f1 = 1;
      if(data[6] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
	    data[5] = 0;
	    data[6] = 0;
    }else{
      data[5] == f;
      data[6] == f;
    } 
    
    if(data[1] == 0 && data[2] == 0){
      if(data[3] == 0&& data[4] == 0){
	if(data[5] == 0&& data[6] == 0){
	  cout << "black" <<endl;
	}else{
	  cout << "blue" << endl;
	}
      }
      else{
	if(data[5] == 0&&data[6] == 0){
	  cout << "linme" << endl;
	  }else{
	  cout << "aqua" << endl;
	}
      }
    }
    if(data[1] == f && data[2] == f){
      if(data[3] == f&& data[4] == f){
	if(data[5] == f&& data[6] == f){
	  cout << "white" <<endl;
	}else{
	  cout << "yellow"<< endl;
	}
      }
      else{
	if(data[5] == 0&&data[6] == 0){
	  cout << "red" << endl;
	  }else{
	  cout << "fuchsia" << endl;
	}
      }
    }
  }
  return 0;
}