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<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] = 225;
  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] == ':';
	if(in[j] == 'b') in[j] == ';';
	if(in[j] == 'c') in[j] == '<';
	if(in[j] == 'd') in[j] == '=';
	if(in[j] == 'e') in[j] == '>';
	if(in[j] == 'f') in[j] == '?';
      }

      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]));

      // cout << d << endl;
      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 <iostream>
#include <string>
#include <cmath>
using namespace std;

const int INF = 1 << 28;

int main ()
{
    int R[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
    int G[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
    int B[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
    string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

    string str;
    while (cin >> str, str != "0") {
        int r = (str[1] - '0') * 16 + (str[2] - '0');
        int g = (str[3] - '0') * 16 + (str[4] - '0');
        int b = (str[5] - '0') * 16 + (str[6] - '0');

        int D = INF;
        string res;
        for (int i = 0; i < 8; i++) {
            int d = ((R[i] - r) * (R[i] - r) + (G[i] - g) * (G[i] - g) + (B[i] - b) * (B[i] - b));
            if (d < D) {
                res = color[i];
                D = d;
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

const int INF = 1 << 28;

int decimal(char a, char b) {
    int d;
    if (isdigit(a)) d += a - '0';
    else d += a - 'a' + 10;
    d *= 16;

    if (isdigit(b)) d += b - '0';
    else d += b - 'a' + 10;
    
    return d;
}

struct color_t {
    int r, g, b;
    color_t(int r=0, int g=0, int b=0) : r(r), g(g), b(b) {}
    color_t(string s) {
        r = decimal(s[1], s[2]);
        g = decimal(s[3], s[4]);
        b = decimal(s[5], s[6]);
    }
};

int square_distance(color_t a, color_t b) {
    return (a.r - b.r) * (a.r - b.r) + (a.g - b.g) * (a.g - b.g) + (a.b - b.b) * (a.b - b.b);
}

int main() {
    string color[8];
    color_t color_v[8];

    color[0] = "black";   color_v[0] = color_t("#000000");
    color[1] = "blue";    color_v[1] = color_t("#0000ff");
    color[2] = "lime";    color_v[2] = color_t("#00ff00");
    color[3] = "aqua";    color_v[3] = color_t("#00ffff");
    color[4] = "red";     color_v[4] = color_t("#ff0000");
    color[5] = "fuchsia"; color_v[5] = color_t("#ff00ff");
    color[6] = "yellow";  color_v[6] = color_t("#ffff00");
    color[7] = "white";   color_v[7] = color_t("#ffffff");

    string s;
    while (getline(cin, s)) {
        if (s == "0") break;
        color_t c(s);
        int min_sq_dist = INF;
        string min_dist_color_name;
        for (int i = 0; i < 8; i++) {
            int sq_dist = square_distance(color_v[i], c);
            //cout << color[i] << ' ' << sq_dist << endl;
            if (min_sq_dist > sq_dist) {
                min_sq_dist = sq_dist;
                min_dist_color_name = color[i];
            }
        }
        cout << min_dist_color_name << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <climits>
using namespace std;

const static int COLOR_NAME_LENGTH = 7;
const static int BASE_COLOR_NUM = 8;
const static int MASK = 0x0000ff;

const int base_colors[ BASE_COLOR_NUM ] = {
  0x000000,
  0x0000ff,
  0x00ff00,
  0x00ffff,
  0xff0000,
  0xff00ff,
  0xffff00,
  0xffffff
};

const char *base_color_names[ BASE_COLOR_NUM ] = {
  "black",
  "blue",
  "lime",
  "aqua",
  "red",
  "fuchsia",
  "yellow",
  "white"
};

int diffsq( const int color1, const int color2 ) {
  int c1 = color1;
  int c2 = color2;
  int rdiff = ( ( c1 >> 16 ) & MASK ) - ( ( c2 >> 16 ) & MASK );
  int gdiff = ( ( c1 >>  8 ) & MASK ) - ( ( c2 >>  8 ) & MASK );
  int bdiff = ( ( c1       ) & MASK ) - ( ( c2       ) & MASK );

  return rdiff * rdiff + gdiff * gdiff + bdiff * bdiff;
}

int main() {

  while( 1 ) {
    char color_name[ COLOR_NAME_LENGTH + 1 ];
    scanf( "%s", color_name );
    if( color_name[ 0 ] == '0' ) {
      return EXIT_SUCCESS;
    }
    for( int i = 1; i < COLOR_NAME_LENGTH + 1; i++ )  {
      color_name[ i - 1 ] = color_name[ i ];
    }
    int color;
    int minidx = 0;
    int mindiff = INT_MAX;
    sscanf( color_name, "%x", &color );
    for( int i = 0; i < BASE_COLOR_NUM; i++ ) {
      int diff = diffsq( color, base_colors[ i ] );
      if( diff < mindiff ) {
        minidx = i;
        mindiff =  diff;
      }
    }
    printf( "%s\n", base_color_names[ minidx ] );
  }
}

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

int main(){
	char pn[8][10] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int pR[8] = {0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff},
		pG[8] = {0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff},
		pB[8] = {0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};
	char c;
	while(scanf(" %c",&c),c!='0'){
		int N; scanf("%x",&N);
		int R = N/(1<<16)%(16*16), G = N/(1<<8)%(16*16), B = N/(1<<0)%(16*16);
		int min_ = INT_MAX,ans;
		for(int i=0;i<8;i++){
			int dR = pR[i]-R, dG = pG[i]-G, dB = pB[i]-B;
			int d = dR*dR+dG*dG+dB*dB;
			if(d<min_){
				min_ = d; ans = i;
			}
		}
		printf("%s\n",pn[ans]);
	}
	return 0;
}