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<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int table[][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}
  };

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

  const int n = sizeof(table) / sizeof(table[0]);

  char buff[256];
  while(fgets(buff,sizeof(buff),stdin), buff[0] != '0'){
    char col[3] = { 0 };
    int rgb[3];
    int diff = INT_MAX;
    int ans;
    REP(i,3){
      col[0] = buff[1 + i*2];
      col[1] = buff[1 + i*2 + 1];

      sscanf(col, "%x", rgb + i);
    }

#define DBL(x) ((x)*(x))
    REP(i,n){
      int tmp = 0;
      REP(j,3)
        tmp += DBL(rgb[j] - table[i][j]);
      if(tmp < diff){
        diff = tmp;
        ans = i;
      }
    }
    puts(name[ans]);
  }

  return 0;
}

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

int checkHeight(double h);
const string COLORS[8] = {"black", "blue", "lime", "aqua"
                         , "red", "fuchsia", "yellow", "white"};

const int RGB_VALUES[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 toDec(char s);

int main()
{
    while(1)
    {
        string in_str;
        cin >> in_str;
        if(in_str == "0")
        {
            break;
        }
        
        int r = toDec(in_str[1]) * 16 + toDec(in_str[2]);
        int g = toDec(in_str[3]) * 16 + toDec(in_str[4]);
        int b = toDec(in_str[5]) * 16 + toDec(in_str[6]);

        double dist_min = 1000000;
        int index = 0;
        for(int i = 0; i < 8; i++)
        {
            double dist_square = (r - RGB_VALUES[i][0]) * (r - RGB_VALUES[i][0])
                                 + (g - RGB_VALUES[i][1]) * (g - RGB_VALUES[i][1])
                                 + (b - RGB_VALUES[i][2]) * (b - RGB_VALUES[i][2]);
            if(isless(dist_square, dist_min))
            {
                dist_min = dist_square;
                index = i;
            }
        }
        cout << COLORS[index] << endl;
    }
    return 0;
}

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

C++: #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
  char c[10];
  int r,g,b,id;
  string str[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  while(scanf("%s",c),c[0]!='0'){
    r = g = b = 0;
    if('0'<=c[1] && c[1]<='9') r += (c[1]-'0')*16;
    else r += (c[1]-'A'+10)*16;
    if('0'<=c[2] && c[2]<='9') r += (c[2]-'0');
    else r += (c[2]-'A'+10);
    if('0'<=c[3] && c[3]<='9') g += (c[3]-'0')*16;
    else g += (c[3]-'A'+10)*16;
    if('0'<=c[4] && c[4]<='9') g += (c[4]-'0');
    else g += (c[4]-'A'+10);
    if('0'<=c[5] && c[5]<='9') b += (c[5]-'0')*16;
    else b += (c[5]-'A'+10)*16;
    if('0'<=c[6] && c[6]<='9') b += (c[2]-'0');
    else r += (c[6]-'A'+10);
    id = 0;
    if(r >=123) id += 4;
    if(g >=123) id += 2;
    if(b >=123) id += 1;
    cout << str[id] << endl;
  }
  return(0);
}

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

typedef long long ll;
typedef pair<int,string> pis;
vector<pis> v;

template<class T>
T sqr(T a) { return a * a; }

int main() {
	string s;

	v.push_back(pis(0x000000, "black"));
	v.push_back(pis(0x0000ff, "blue"));
	v.push_back(pis(0x00ff00, "lime"));
	v.push_back(pis(0x00ffff, "aqua"));
	v.push_back(pis(0xff0000, "red"));
	v.push_back(pis(0xff00ff, "fuchsia"));
	v.push_back(pis(0xffff00, "yellow"));
	v.push_back(pis(0xffffff, "white"));

	while(cin >> s, s[0]-'0') {
		int a = 0;
		for(int i = 0; i < 6; i++) {
			a *= 16;
			if(0 <= s[i+1] && s[i+1] <= '9')
				a += s[i+1] - '0';
			else
				a += s[i+1] - 'a' + 10;
		}

		int res = -1;
		ll mn = 1e9;
		for(int i = 0; i < v.size(); i++) {
			ll tmp = 0;
			for(int j = 0; j < 3; j++) {
				tmp += sqr(((v[i].first >> (j * 8)) & 0xff) - ((a >> (j * 8)) & 0xff));
			}
			if(tmp < mn) {
				mn = tmp;
				res = i;
			}
		}
		cout << v[res].second << endl;
	}
}