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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct color {
	int r, g, b;
};
map<string, color>mp{
	{"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}}
};
int main() {
	string s;
	while (cin >> s, s != "0") {
		int r, g, b;
		sscanf(s.data(), "%*c%2x%2x%2x", &r, &g, &b);
		int Min = INT_MAX;
		string ans;
		for (auto p : mp) {
			int d = abs((r - p.second.r)*(r - p.second.r) + (g - p.second.g)*(g - p.second.g) + (b - p.second.b)*(b - p.second.b));
			if (d < Min) {
				Min = d;
				ans = p.first;
			}
		}
		cout << ans << endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
string color(int x) {
	switch (x) {
	case 0:return "black";
	case 1:return "blue";
	case 2:return "lime";
	case 3:return "aqua";
	case 4:return "red";
	case 5:return "fuchsia";
	case 6:return "yellow";
	case 7:return "white";
	default:return "gray";
	}
}

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

int main() {

	map<int, vector<double> >m;
	m[0].push_back(0x00);
	m[0].push_back(0x00);
	m[0].push_back(0x00);
	m[1].push_back(0x00);
	m[1].push_back(0x00);
	m[1].push_back(0xff);
	m[2].push_back(0x00);
	m[2].push_back(0xff);
	m[2].push_back(0x00);
	m[3].push_back(0x00);
	m[3].push_back(0xff);
	m[3].push_back(0xff);
	m[4].push_back(0xff);
	m[4].push_back(0x00);
	m[4].push_back(0x00);
	m[5].push_back(0xff);
	m[5].push_back(0x00);
	m[5].push_back(0xff);
	m[6].push_back(0xff);
	m[6].push_back(0xff);
	m[6].push_back(0x00);
	m[7].push_back(0xff);
	m[7].push_back(0xff);
	m[7].push_back(0xff);

	vector<double>d(8);

	string s;

	while (cin >> s, s != "0") {

		double r, g, b;

		r = h(s[1]) * 16 + h(s[2]); //cout << "red is " << r << endl;
		g = h(s[3]) * 16 + h(s[4]); //cout << "green is " << g << endl;
		b = h(s[5]) * 16 + h(s[6]); //cout << "blue is " << b << endl;

		for (int i = 0; i < 8; i++) {

			d[i] = pow(pow(r - m[i][0], 2) + pow(g - m[i][1], 2) + pow(b - m[i][2], 2), 0.5);
		//	cout << d[i] << " ";
		}//cout << endl;
		cout << color(distance(d.begin(),min_element(d.begin(), d.end()))) << 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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int hen(char a) {
  if((int)a - 48 >= 0 && (int)a - 48 < 10) return (int)a - 48;
  if(a == 'a') return 10;
  else if(a == 'b') return 11;
  else if(a == 'c') return 12;
  else if(a == 'd') return 13;
  else if(a == 'e') return 14;
  else return 15;
}

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

    int ans = INT_MAX;
    string mans;
    if(r * r + g * g + b * b < ans) ans = r * r + g * g + b * b, mans = "brack";
    if(r * r + g * g + (b - 255) * (b - 255) < ans) ans = r * r + g * g + (b - 255) * (b - 255), mans = "blue";
    if(r * r + (g - 255) * (g - 255) + b * b < ans) ans = r * r + (g - 255) * (g - 255) + b * b, mans = "lime";
    if(r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "	aqua";
    if((r - 255) * (r - 255) + g * g + b * b < ans) ans = (r - 255) * (r - 255) + g * g + b * b, mans = "red";
    if((r - 255) * (r - 255) + g * g + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + g * g + (b - 255) * (b - 255), mans = "fuchsia";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b, mans = "yello";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "white";

    cout << mans << endl;
  }
}

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

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

int dis(int id, vector<int> a){
  int res = 0;
  for(int i=0;i<3;i++){
    int comp = 0;
    if(id&1) comp = 255;
    res += (a[i]-comp)*(a[i]-comp);
    id/=2;
  }
  return res;
}

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

int main(){
  string s;
  while(cin >> s, s != "0"){
    vector<int> a(3);
    for(int i=0;i<3;i++){
      a[i] = toDec(s[2*i+1])*16 + toDec(s[2*i+2]);
    }
    int ans = 0, dmin = dis(0,a);
    for(int i=1;i<8;i++){
      if(dis(i,a) < dmin){
        ans = i; dmin = dis(i,a);
      }
    }
    cout << colors[ans] << endl;
  }
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
string color[] = {"black", "blue", "lime", "aqua",
    "red", "fuchsia", "yellow", "white"};
int nums[][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 convert(string str) {
    int res = 0;
    if ('0'<=str[0]&&str[0]<='9') {
        res += (str[0]-'0') * 16;
    } else if ('a'<=str[0]&&str[0]<='f') {
        res += (str[0]-'a'+10) * 16;
    }
    if ('0'<=str[1]&&str[1]<='9') {
        res += (str[1]-'0');
    } else if ('a'<=str[1]&&str[1]<='f') {
        res += (str[1]-'a'+10);
    }
    return res;
}

int main() {
    string str;
    while (cin >> str) {
        if (str == "0") break;
        double d = 10000000.0;
        string res;
        int r = convert(str.substr(1,2)), g = convert(str.substr(3,2)), b = convert(str.substr(5,2));
        for (int i=0; i<8; i++) {
            double tmp = sqrt(pow(r-nums[i][0], 2)+pow(g-nums[i][1], 2)+pow(b-nums[i][2], 2));
            if (tmp < d) {
                d = tmp;
                res = color[i];
            }
        }
        cout << res << endl;
    }
}