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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  char str[8][10]={"black","blue","lime","aqua",
		   "red","fuchsia","yellow","white"};
  int col[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(1){
    string s;
    cin>>s;
    if(s=="0")break;
    vi v(3,0);
    rep(i,3){
      if('a'<=s[i*2+1] && s[i*2+1]<='f')v[i]+=10+(s[i*2+1]-'a');
      else v[i]+=s[i*2+1]-'0';
      v[i]*=16;
      if('a'<=s[i*2+2] && s[i*2+2]<='f')v[i]+=10+(s[i*2+2]-'a');
      else v[i]+=s[i*2+2]-'0';
    }
    int ans=INF;
    rep(i,8){
      int tmp=0;
      rep(j,3)tmp+=(col[i][j]-v[j])*(col[i][j]-v[j]);
      ans=min(ans,tmp);
    }
    rep(i,8){
      int tmp=0;
      rep(j,3)tmp+=(col[i][j]-v[j])*(col[i][j]-v[j]);
      if(tmp==ans){
	cout<<str[i]<<endl;
	break;
      }
    }

  }
}

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 s;
  while(cin>>s,s!="0"){
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(s,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(s,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

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

const int RGB[][ 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 xtod( char* c )
{
	int ret = 0;
	int mag = 16;
	for( int i = 0; i < 2; ++i, ++c ){
		int d = 0;
		if( *c >= '0' && *c <= '9' ){
			d = *c - '0';
		}else{
			d = *c - 'a' + 10;
		}
		ret += ( d * mag );
		mag /= 16;
	}
	return ret;
}

int distance( const int* o, int* x )
{
	int dd[ 3 ];
	for( int i = 0; i < 3; ++i ){
		dd[ i ] = x[ i ] - o[ i ];
		dd[ i ] *= dd[ i ];
	}
	return dd[ 0 ] + dd[ 1 ] + dd[ 2 ];
}

int main()
{
	char col[ 8 ];

	while( cin >> col && *col != '0' ){
		int n[ 3 ];
		for( int i = 0; i < 3; ++i ){
			n[ i ] = xtod( col + ( 1 + i * 2 ) );
		}
		int d[ 8 ];
		for( int i = 0; i < 8; ++i ){
			d[ i ] = distance( RGB[ i ], n );
		}
		int ans = 0;
		int ansD = 200000;
		for( int i = 0; i < 8; ++i ){
			if( d[ i ] < ansD ){
				ans = i;
				ansD = d[ i ];
			}
		}
		cout << color[ ans ] << endl;
	}

	return 0;
}

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

int six_ten(char x){
	if(x >= '0' && x <= '9'){
		return x - '0';
	}
	else{
		return 10 + (x - 'a');
	}
}
 
int main(){
    int color_data[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 color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	string s;
	while(true){
		cin >> s;
		if(s == "0")break;
		int r,g,b;
		r = 16 * six_ten(s[1]) + six_ten(s[2]);
		g = 16 * six_ten(s[3]) + six_ten(s[4]);
		b = 16 * six_ten(s[5]) + six_ten(s[6]);

		double maxi = DBL_MAX;
		int key;
		for(int i = 0; i < 8; i++){
			double R = r - color_data[i][0];
			double G = g - color_data[i][1];
			double B = b - color_data[i][2];
			R *= R;
			G *= G;
			B *= B;
			double RGB = sqrt(R + G + B);
			if(RGB < maxi){
				maxi = RGB;
				key = i;
			}
		}
		cout << color[key] << endl;
	}
    return 0;
}

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


int main(int argc, const char * argv[]) {
    
    while (true) {
        string input;
        cin >> input;
        if(input == "0"){
            break;
        }

        int red = stoi(input.substr(1,2), NULL, 16);
        int green = stoi(input.substr(3,2), NULL, 16);
        int blue = stoi(input.substr(5,2), NULL, 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;
}