Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int h(string s){
	int ret = 0;
	int src = 1;
	for(int i=s.length()-1;i>=0;i--){
		ret += (s[i]>'9'?s[i]-'a'+10:s[i]-'0')*src;
		src *= 16;
	}
	return ret;
}

double f(string a,string b){	
	string tr,tg,tb;
	string tr2,tg2,tb2;
	tr = a.substr(1,2);
	tg = a.substr(3,2);
	tb = a.substr(5,2);
	tr2 = b.substr(1,2);
	tg2 = b.substr(3,2);
	tb2 = b.substr(5,2);
	return sqrt(
		(h(tr)-h(tr2))*(h(tr)-h(tr2)) +
		(h(tg)-h(tg2))*(h(tg)-h(tg2)) +
		(h(tb)-h(tb2))*(h(tb)-h(tb2))
	);
}
int main(){
	double MIN;
	string ret;
	
	string rgb;
	while(cin >> rgb && rgb[0] != '0'){
		MIN = (1<<21);
		if(MIN >     f(rgb,"#000000")){
			MIN = f(rgb,"#000000");
			ret = "black";
		}
		if(MIN >     f(rgb,"#0000ff")){
			MIN = f(rgb,"#0000ff");
			ret = "blue";
		}
		if(MIN >     f(rgb,"#00ff00")){
			MIN = f(rgb,"#00ff00");
			ret = "lime";
		}
		if(MIN >     f(rgb,"#00ffff")){
			MIN = f(rgb,"#00ffff");
			ret = "aqua";
		}
		if(MIN >     f(rgb,"#ff0000")){
			MIN = f(rgb,"#ff0000");
			ret = "red";
		}
		if(MIN >     f(rgb,"#ff00ff")){
			MIN = f(rgb,"#ff00ff");
			ret = "fuchsia";
		}
		if(MIN >     f(rgb,"#ffff00")){
			MIN = f(rgb,"#ffff00");
			ret = "yellow";
		}
		if(MIN >     f(rgb,"#ffffff")){
			MIN = f(rgb,"#ffffff");
			ret = "white";
		}
		cout << ret << endl;

	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

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

int rs[] = {
	0, 0, 0, 0, 255, 255, 255, 255
};

int gs[] = {
	0, 0, 255, 255, 0, 0, 255, 255
};

int bs[] = {
	0, 255, 0, 255, 0, 255, 0, 255,
};

int get_num(char c1, char c2){
	int res = 0;
	if(isdigit(c1)) res += c1 - '0';
	else res += c1 - 'a' + 10;
	res *= 16;
	if(isdigit(c2)) res += c2 - '0';
	else res += c2 - 'a' + 10;
	return res;
}

int pow(int n){ return n * n;}

int get_d(int id, int r, int g, int b){
	return pow(rs[id] - r) + pow(gs[id] - g) + pow(bs[id] - b);
}

int main(){
	string s;
	int r, g, b;
	while(cin >> s && s != "0"){
		int best;
		int p = INF;
		r = get_num(s[1], s[2]);
		g = get_num(s[3], s[4]);
		b = get_num(s[5], s[6]);
		rep(i, 8){
			int c = get_d(i, r, g, b);
			if(c < p){
				best = i;
				p = c;
			}
		}
		cout << cs[best] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
using namespace std;
int Overten(char a){
  if(a-'0'<10)return a-'0';
  if(a=='A')return 10;
  if(a=='B')return 11;
  if(a=='C')return 12;
  if(a=='D')return 13;
  if(a=='E')return 14;
  if(a=='F')return 15;
}
int changeDtoI(char a,char b){
  return Overten(a)*16+Overten(b);
}
int main(void){
  string color;
  while(cin>>color,color.size()>3){
    int R = changeDtoI(color[1],color[2])<128?0:1;
    int G = changeDtoI(color[3],color[4])<128?0:1;
    int B = changeDtoI(color[4],color[5])<128?0:1;
    //cout<<R << " " << G << " " << B <<endl;
    if(R * G * B)cout<<"white"<<endl;
    else if(R * G)cout<<"yellow"<<endl;
    else if(R * B)cout<<"fuchsia"<<endl;
    else if(G * B)cout<<"aqua"<<endl;
    else if(R)cout<<"red"<<endl;
    else if(G)cout<<"green"<<endl;
    else if(B)cout<<"blue"<<endl;
    else cout<<"black"<<endl;
  }
}

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

    int d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = (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;
}