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<string>
#include<cmath>
using namespace std;
int main() {
	string a;
	string c[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int 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} };
	while (cin>>a&&a!="0")
	{
		double t[3];
		for (int i = 1; i < a.length(); i += 2) {
			double b = 0;
			for (int j = 0; j <= 1; j++) {
				if ((int)a[i + j] >= '0' && (int)a[i +j] <= '9')
					b += (pow(16, (j+1)%2)*(int)(a[i +j] - '0'));
				else 
					b += (pow(16, (j+1)%2)*(10 + (int)a[i + j] - 'a'));
			}
			t[(i - 1) / 2] = b;
		}
		double e = 100000;
		string f = "";
		for (int i = 7; i >= 0; i--) {
			double g = sqrt(pow((t[0] - d[i][0]), 2) + pow((t[1] - d[i][1]), 2) + pow((t[2] - d[i][2]), 2));
			if (g <= e) {
				e = g;
				f = c[i];
			}
		}
		cout << f << endl;
	}
}

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

int parse(string s){
	int tmp = 0;
	if(s[0] >= 'a' && s[0] <= 'f') tmp = s[0] - 'a' + 10;
	else tmp = s[0] - '0';
	if(s[1] >= 'a' && s[1] <= 'f') tmp = tmp * 16 + s[1] - 'a' + 10;
	else tmp = tmp * 16 + s[1] - '0';
	return tmp;
}

int main(){
	string s;
	string name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int color[3][8] = {{0,0,0,0,255,255,255,255},{0,0,255,255,0,0,255,255},{0,255,0,255,0,255,0,255}};
	while(1){
		int d[8] = {};
		cin >> s;
		if(s == "0") break;
		for(int i = 0;i < 3;i++){
			int num = parse(s.substr(i * 2 + 1,2));
			for(int j = 0;j < 8;j++){
				d[j] += (num - color[i][j]) * (num - color[i][j]);
			}
		}
		int mi = 1e+9,clr;
		for(int i = 0;i < 8;i++){
			if(mi > d[i]){
				mi = d[i];
				clr = i;
			}
		}
		cout << name[clr] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"}, {"yellow","white"} } };
char T[9] = "89abcdef";
int a, b, c;
int main() {
	while (true) {
		a = 0; b = 0; c = 0;
		cin >> S;
		if (S == "0") { break; }
		for (int i = 0; i < 8; i++){
			if (T[i] == S[1]) {
				a = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[3]) {
				b = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[5]) {
				c = 1;
			}
		}
		cout << x[a][b][c] << endl;
	}
}

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

        double D = INF;
        string res;
        for (int i = 0; i < 8; i++) {
            double d = sqrt((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>
using namespace std;
string str;
string ta[8] = {"black","blue","lime","aqua",
		"red","fuchsia","yellow","white"};

string tb[8] = {"#000000","#0000ff","#00ff00","#00ffff",
                "#ff0000","#ff00ff","#ffff00","#ffffff"};
int tab[8];
int mini,miniNo;

/*
string d(int in){
  if(in==0)return "0";  if(in==8)return "8";
  if(in==1)return "1";  if(in==9)return "9";
  if(in==2)return "2";  if(in==15)return "f";
  if(in==3)return "3";  if(in==14)return "e";
  if(in==4)return "4";  if(in==13)return "d";
  if(in==5)return "5";  if(in==12)return "c";
  if(in==6)return "6";  if(in==11)return "b";
  if(in==7)return "7";  if(in==1.)return "a";
}
*/
int c(char ch){
  if('a'<=ch&&ch<='f')return 10+(ch-'a');
  return ch-'0';
}

int b(string x,string y){
  int X = c(x[0])*16 + c(x[1]);
  int Y = c(y[0])*16 + c(y[1]);
  int Z = X - Y;
  //string z= d(Z/16)+d(Z%16);
  return Z*Z;
}
string compute(){
  
}
int main(){
  while(1){
    mini=99999;
    cin>>str;
    if(str=="0")break;
    for(int i=0;i<8;i++){
      tab[i] =b( tb[i].substr(1,2) , str.substr(1,2) );
      tab[i]+=b( tb[i].substr(3,2) , str.substr(3,2) );
      tab[i]+=b( tb[i].substr(5,2) , str.substr(5,2) );
      if(mini>tab[i]){
	mini=tab[i];
	miniNo=i;
      }
    }
    cout<<ta[miniNo]<<endl;
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

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

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

int main() {
	string str;
	while(cin>>str,str!="0"){
		int r,g,b;
		r=x(str[1])*16+x(str[2]);
		g=x(str[3])*16+x(str[4]);
		b=x(str[5])*16+x(str[6]);
//cout<<r<<" "<<g<<" "<<b<<endl;
		int i;
		string res="";
		int re=1000000000;
		for(i=0;i<8;i++){
			if(re>(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0))){
				res=color[i];
				re=(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0));
			}
		}
		cout<<res<<endl;
	}
	return 0;
}