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

int main(){

	int color[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}};
	double d, f, p[3];
	string str, c;

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

		d = sqrt(3 * pow(255, 2));
		for(int j=0; j<3; j++){
			if(str[2*j+1] >= '0' && str[2*j+1] <= '9') p[j] = 16 * (str[2*j+1] - '0');
			else p[j] = 16 * (10.0 + str[2*j+1] - 'a');
				
			if(str[2*j+2] >= '0' && str[2*j+2] <= '9') p[j] += str[2*j+2] - '0';
			else p[j] += 10.0 + str[2*j+2] - 'a';
		}
		
		for(int i=0; i<8; i++){
			f = sqrt(pow(p[0] - color[i][0], 2) + pow(p[1] - color[i][1], 2) + pow(p[2] - color[i][2], 2));
			if(d > f){
				d = f;
				switch(i){
					case 0: c = "black"; break;
					case 1: c = "blue"; break;
					case 2: c = "lime"; break;
					case 3: c = "aqua"; break;
					case 4: c = "red"; break;
					case 5: c = "fuchsia"; break;
					case 6: c = "yellow"; break;
					case 7: c = "white"; break;
				}
			}
		}
		
		cout << c << endl;
	}

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int rgb[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 name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int sqr(int x) { return x * x; }

void search(string str) {
	string input = str.substr(1, 2) + " " + str.substr(3, 2) + " " + str.substr(5, 2);
	
	int col[3];
	sscanf(input.c_str(), "%x %x %x", &col[0], &col[1], &col[2]);
	
	int min_dst = 1L << 30, ans = -1;
	
	for_(i,0,8) {
		int dst = 0;
		
		for_(j,0,3) {
			dst += sqr(rgb[i][j] - col[j]);
		}
		
		if (min_dst > dst) {
			min_dst = dst;
			ans = i;
		}
	}
	
	cout << name[ans] << endl;
}

int main() {
	string str;
	while (cin >> str, str != "0") search(str);
}

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[6]-'0');
    else b += (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<cmath>
using namespace std;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
int stoi(char c){
  if('0' <= c && c <= '9')
    return c - '0';
  return c - 'a' + 10;
}

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

int main(void){
  string s;
  string ans[8] = {
    "black",//	00	00	00
    "blue",//	00	00	ff
    "lime",//	00	ff	00
    "aqua",//	00	ff	ff
    "red",//	ff	00	00
    "fuchsia",//	ff	00	ff
    "yellow",//	ff	ff	00
    "white"//	ff	ff	ff
  };
  int num[8];
  int cnt = 0;
  rep(i,8)num[i] = i * 255;     
  while(cin>>s){
    if(s == "0")break;
    int in[3];
    in[0] = stoi(s[1]) * 16 + stoi(s[2]);
    in[1] = stoi(s[3]) * 16 + stoi(s[4]);
    in[2] = stoi(s[5]) * 16 + stoi(s[6]);
    //rep(i,3)cout<<in[i]<<endl;
    int index = 0;
    unsigned long long diff = 100000000;
    rep(i,8){

      int box[3];
      rep(j,3){
	box[j] = (i>>(2-j))%2*255;
      }
      
     
      unsigned long long int calc = 0;
      rep(j,3)calc += pow(in[j] - box[j]);
     	
      if(calc < diff){
	diff = calc;
	index = i;
      }
    }
    cout<<ans[index]<<endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	char l[6];
	string s;
	while (cin >> s) {
		for (int i = 0; i < 6; i++) {
			l[i] = s[i + 1];
		}
		int r, g, b;
		int z[6];

		for (int i = 0; i < 6; i++) {
			if (l[i] == '0') {
				z[i] = 0;
			}
			else if (l[i] == '1') {
				z[i] = 1;
			}
			else if (l[i] == '2') {
				z[i] = 2;
			}
			else if (l[i] == '3') {
				z[i] = 3;
			}
			else if (l[i] == '4') {
				z[i] = 4;
			}
			else if (l[i] == '5') {
				z[i] = 5;
			}
			else if (l[i] == '6') {
				z[i] = 6;
			}
			else if (l[i] == '7') {
				z[i] = 7;
			}
			else if (l[i] == '8') {
				z[i] = 8;
			}
			else if (l[i] == '9') {
				z[i] = 9;
			}			
			else if (l[i] == 'a') {
				z[i] = 10;
			}
			else if (l[i] == 'b') {
				z[i] = 11;
			}
			else if (l[i] == 'c') {
				z[i] = 12;
			}
			else if (l[i] == 'd') {
				z[i] = 13;
			}
			else if (l[i] == 'e') {
				z[i] = 14;
			}
			else if (l[i] == 'f') {
				z[i] = 15;
			}
		}

		r = z[0] * 16 + z[1];
		g = z[2] * 16 + z[3];
		b = z[4] * 16 + z[5];

		
		//ff == 255;
		if (r <= 128) {
			//black,blue,lime,aqua
			if (g <= 128) {
				//black,blue
				if (b <= 128) {
					cout << "black";
				}
				else {
					cout << "blue";
				}
			}
			else {
				//lime,aqua
				if (b <= 128) {
					cout << "lime";
				}
				else {
					cout << "aqua";
				}
			}
		}
		else {
			//red,fuchsia,yellow,white
			if (g <= 128) {
				//red,fu
				if (b <= 128) {
					cout << "red";
				}
				else {
					cout << "fuchsia";
				}
			}
			else {
				if (b <= 128) {
					cout << "yellow";
				}
				else
				{
					cout << "white";
				}
			}
		}
		cout << endl;
	}

	return 0;
}