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<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int d[2] = { 0,255 };
int b(char c) {
	if (c <= '9')return c - '0';
	return c - 'a' + 10;
}
int c(string d) {
	return b(d[0]) * 16 + b(d[1]);
}
int main() {
	string a;
	while (cin >> a, a != "0") {
		int o = 0, p = 0, q = 0;
		int x = c(a.substr(1, 2)), y = c(a.substr(3, 2)), z = c(a.substr(5, 2));
		int MIN = 1 << 29;
		for (int e = 0; e < 2; e++) {
			for (int f = 0; f < 2; f++) {
				for (int g = 0; g < 2; g++) {
					if ((x - d[e])*(x - d[e]) + (y - d[f])*(y - d[f]) + (z - d[g])*(z - d[g]) < MIN) {
						MIN = (x - d[e])*(x - d[e]) + (y - d[f])*(y - d[f]) + (z - d[g])*(z - d[g]);
						o = e; p = f; q = g;
					}
				}
			}
		}
		if (o) {
			if (p) {
				if (q) {
					puts("white");
				}
				else {
					puts("yellow");
				}
			}
			else {
				if (q) {
					puts("fuchsia");
				}
				else {
					puts("red");
				}
			}
		}
		else {
			if (p) {
				if (q) {
					puts("aqua");
				}
				else {
					puts("lime");
				}
			}
			else {
				if (q) {
					puts("blue");
				}
				else {
					puts("black");
				}
			}
		}
	}
}

C++: #include<iostream>
#include<map>
#include<math.h>

using namespace std;

map<int, int> MR;
map<int, int> MG;
map<int, int> MB;

void make(){
  MR[0] = 0;
  MG[0] = 0;
  MB[0] = 0;
  MR[1] = 0;
  MG[1] = 0;
  MB[1] = 255;
  MR[2] = 0;
  MG[2] = 255;
  MB[2] = 0;
  MR[3] = 0;
  MG[3] = 255;
  MB[3] = 255;
  MR[4] = 255;
  MG[4] = 0;
  MB[4] = 0;
  MR[5] = 255;
  MG[5] = 0;
  MB[5] = 255;
  MR[6] = 255;
  MG[6] = 255;
  MB[6] = 0;
  MR[7] = 255;
  MG[7] = 255;
  MB[7] = 255;
}

int main(){

  make();

  char in[2];
  int status = 0;

  while(cin >> in[0]){
    if(in[0] == '0') break;

    int r, g, b;

    for(int i = 0; i < 3; i++){
      
      cin >> in[0] >> in[1];

      for(int j = 0; j <= 1; j++){
	if(in[j] == 'a') in[j] -= 39;
	if(in[j] == 'b') in[j] -= 39;
	if(in[j] == 'c') in[j] -= 39;
	if(in[j] == 'd') in[j] -= 39;
	if(in[j] == 'e') in[j] -= 39;
	if(in[j] == 'f') in[j] -= 39;
      }

      if(i == 0) r = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 1) g = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 2) b = (in[0] - 48) * 16 + (in[1] - 48);
    }

    double d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = sqrt((r - MR[j])*(r - MR[j])+(g - MG[j])*(g - MG[j])+(b - MB[j])*(b - MB[j]));
      if(j == 0 || min > d){
	min = d;
	then = j;
      }
    }

    if(then == 0) cout << "black" <<endl;
    if(then == 1) cout << "blue" <<endl;
    if(then == 2) cout << "lime" <<endl;
    if(then == 3) cout << "aqua" <<endl;
    if(then == 4) cout << "red" <<endl;
    if(then == 5) cout << "fuchsia" <<endl;
    if(then == 6) cout << "yellow" <<endl;
    if(then == 7) cout << "white" <<endl;

  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

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

int main() {
  
  int colR[8];
  int colG[8];
  int colB[8];
  
  for(int i=0; i<8; i++) {
    colR[i] = i & 1 ? 255 : 0;
    colG[i] = i & 2 ? 255 : 0;
    colB[i] = i & 4 ? 255 : 0;
  }
  
  string s;
  
  while(cin >> s) {
    if(s == "0") break;
    
    s = s.substr(1);
    
    int R = (c(s[0]))*16 + (c(s[1]));
    int G = (c(s[2]))*16 + (c(s[3]));
    int B = (c(s[4]))*16 + (c(s[5]));
    
    int minD = (int)1e9;
    int id = -1;
    for(int i=0; i<8; i++) {
      if( minD > pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0) ) {
	id = i;
	minD = pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0);
      }
    }
    
    cout << colors[id] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int num[1000];
const string ans[] = {"black","blue","lime","aqua","red",
		      "fuchsia","yellow","white"};
int ff = 15*16 + 15;
int RGB[][3] = {{0,0,0},
		{0,0,ff},
		{0,ff,0},
		{0,ff,ff},
		{ff,0,0},
		{ff,0,ff},
		{ff,ff,0},
		{ff,ff,ff}};

int _16to10(string a){
  return num[a[0]] * 16 + num[a[1]];
}
int main(){
  num['1'] = 1,  num['2'] = 2,  num['3'] = 3,  num['4'] = 4,num['5'] = 5,num['6'] = 6,num['7'] = 7,num['8'] = 8,num['9'] = 9,num['a'] = 10,num['b'] = 11,  num['c'] = 12,  num['d'] = 13,  num['e'] = 14,num['f'] = 15;
  string color;
  while(cin >> color,color[0] !='0') {
    string r,g,b;
    r = color.substr(1,2);
    g = color.substr(3,2);
    b = color.substr(5,2);
    int rnum,gnum,bnum;
    rnum = _16to10(r);
    gnum = _16to10(g);
    bnum = _16to10(b);
    double mn = 1000000000;
    string anscolor;
    for(int i = 7 ; i >= 0 ; i-- ){
      double dk = pow(rnum-RGB[i][0],2)+pow(gnum-RGB[i][1],2)+pow(bnum-RGB[i][2],2);
      if(mn >= dk){
	mn = dk;
	anscolor = ans[i];
      }
    } 
    cout << anscolor << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

double x(string s) {
  double a=1,ans=0;
  rrep(i,2) {
    if(isdigit(s[i])) ans+=(int)(s[i]-'0')*a;
    else ans+=((int)(s[i]-'a')+10)*a;
    a*=16;
  }
  return ans;
}

int main() {
  double d[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 c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  string s;
  while(cin >> s && s!="0") {
    int ans=0;
    double min=MAX;
    double z[3];
    s=s.substr(1);
    rep(i,3) z[i]=x(s.substr(i*2,2));
    rep(i,8) {
      double v=sqrt((z[0]-d[i][0])*(z[0]-d[i][0])+(z[1]-d[i][1])*(z[1]-d[i][1])+(z[2]-d[i][2])*(z[2]-d[i][2]));
      if(v<min) {
	ans=i;
	min=v;
      }
    }
    pr(c[ans]);
  }
  return 0;
}

C++: #include<cstdio>

using namespace std;

int main(){
	char *color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int rgb[][3]={{0x00,0x00,0x00},
				  {0x00,0x00,0xff},
				  {0x00,0xff,0x00},
				  {0x00,0xff,0xff},
				  {0xff,0x00,0x00},
				  {0xff,0x00,0xff},
				  {0xff,0xff,0x00},
				  {0xff,0xff,0xff}};

	for(char sam[8];scanf("%s",sam),sam[0]-'0';){
		int b;	sscanf(sam+5,"%x",&b);	sam[5]='\0';
		int g;	sscanf(sam+3,"%x",&g);	sam[3]='\0';
		int r;	sscanf(sam+1,"%x",&r);
		int dmin=1000000,imin;
		for(int i=0;i<8;i++){
			int dis=(r-rgb[i][0])*(r-rgb[i][0])+(g-rgb[i][1])*(g-rgb[i][1])+(b-rgb[i][2])*(b-rgb[i][2]);
			if(dis<dmin)	dmin=dis,imin=i;
		}
		puts(color[imin]);
	}

	return 0;
}