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

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

C++: #include<iostream>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=(s[1]-'0')*16+(s[2]-'0');
  int green=(s[3]-'0')*16+(s[4]-'0');
  int blue=(s[5]-'0')*16+(s[6]-'0');
  return sqrt(pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2));
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

inline ll digit(char c) {
    return '0' <= c && c <= '9' ? c - '0' : c - 'a' + 10;
}

int main() {

    vector<string> clr = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
    vector<vector<ll>> clrv = {
        {0, 0, 0},
        {0, 0, 0xff},
        {0, 0xff, 0},
        {0, 0xff, 0xff},
        {0xff, 0, 0},
        {0xff, 0, 0xff},
        {0xff, 0xff, 0},
        {0xff, 0xff, 0xff}
    };

    string cl;
    while (cin >> cl, cl != "0") {

        ll r = digit(cl[1]) * 16 + digit(cl[2]);
        ll g = digit(cl[3]) * 16 + digit(cl[4]);
        ll b = digit(cl[5]) * 16 + digit(cl[6]);

        ll d2min = 0x7FFFFFFFFFFFFFFFLL, did = -1;
        for (ll i = 8; i--; ) {
            ll dr = clrv[i][0] - r;
            ll dg = clrv[i][1] - g;
            ll db = clrv[i][2] - b;
            ll d2 = dr*dr + dg*dg + db*db;
            if (d2min > d2) {
                d2min = d2;
                did = i;
            }
        }
        cout << clr[did] << "\n";
        
    }

}

C++: #include <iostream>

using namespace std;


int main(int argc, const char * argv[]) {
    
    while (true) {
        string input;
        cin >> input;
        if(input == "0"){
            break;
        }
        
/*        for(int i=1;i<7;i++){
            input[i] = toupper(input[i]);
        }
*/
        int red = stoi(input.substr(1,2), nullptr, 16);
        int green = stoi(input.substr(3,2), nullptr, 16);
        int blue = stoi(input.substr(5,2), nullptr, 16);
        
        
        red = (red < 128) ? 0 : 255;
        green = (green < 128) ? 0 : 255;
        blue = (blue < 128) ? 0 : 255;
        
        if(red == 0){
            if(green == 0){
                if(blue == 0){
                    cout << "black" << endl;
                }
                else{
                    cout << "blue" << endl;
                }
                
            }
            else{
                if(blue == 0){
                    cout << "lime" << endl;
                }
                else{
                    cout << "aqua" << endl;
                }
            }
        }
        else{
            if(green == 0){
                if(blue == 0){
                    cout << "red" << endl;
                }
                else{
                    cout << "fuchsia" << endl;
                }
                
            }
            else{
                if(blue == 0){
                    cout << "yellow" << endl;
                }
                else{
                    cout << "white" << endl;
                }
            }
        }
        
    }
    
    return 0;
}