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 <cstdio>
using namespace std;

#define sq(x) ((x)*(x))

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

int color_rgb[8][3] = {
	{ 0x00, 0x00, 0x00 },
	{ 0x00, 0x00, 0xff },
	{ 0x00, 0xff, 0x00 },
	{ 0x00, 0xff, 0xff },
	{ 0xff, 0x00, 0x00 },
	{ 0xff, 0x00, 0xff },
	{ 0xff, 0xff, 0x00 },
	{ 0xff, 0xff, 0xff },
};

int main( void )
{
	string input;
	while ( 1 )
	{
		cin >> input;
		if ( input == "0" ) break;
		int r, g, b;
		sscanf( input.c_str(), "#%2x%2x%2x", &r, &g, &b );

		int min_value = 1 << 28, min_no = 0;
		for ( int i = 0; i < 8; i++ )
		{
			int d = sq(r-color_rgb[i][0]) + sq( g-color_rgb[i][1] ) + sq(b-color_rgb[i][2]);
			if ( d < min_value )
			{
				min_value = d;
				min_no = i;
			}
		}

		cout << color_name[min_no] << endl;
	}
	return 0;
}

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

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

int to(char c){
	if( c >= 'a' ) return 10 + c - 'a';
	return c - '0';
}

int main(){
	string s;
	while(cin >> s && s != "0"){
		int r = to(s[1])*16+to(s[2]);
		int g = to(s[3])*16+to(s[4]);
		int b = to(s[5])*16+to(s[6]);
		vector< pair<int,int> > answer;
		for(int i = 0 ; i < 8 ; i++){
			int R = (i>>2&1)*255;
			int G = (i>>1&1)*255;
			int B = (i&1)*255;
			int dist = (R-r)*(R-r) + (g-G)*(g-G) + (b-B)*(b-B);
			//cout << R <<" " << G << " " << B << " " <<  endl;
			answer.push_back( make_pair(dist,i) );
		}
		cout << table[(*min_element(answer.begin(),answer.end())).second] << endl;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
unsigned int hexToUInt(const std::string &str)
{
  unsigned int val = 0;
  unsigned int v;
  for(size_t ix = 0; ix != str.size(); ++ix) {
    char ch = str[ix];
    if( ch >= '0' && ch <= '9' )
      v = ch - '0';
    else if( ch >= 'A' && ch <= 'F' )
      v = ch - 'A' + 10;
    else if( ch >= 'a' && ch <= 'f' )
      v = ch - 'a' + 10;
    else
      continue;    // 16?????°????????§???????????´???
    val = val * 16 + v;
  }
  return val;
}
void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

const string li[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000","#ff00ff","#ffff00","#ffffff"};
const string name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int cola[3],colb[8][3];
  rep(k,8){
    string str = "";
    REP(i,1,li[k].size()){
      if(i % 2){
        str += li[k][i];
      }
      else{
        str += li[k][i];
        colb[k][i/2-1] = hexToUInt(str);
        str.clear();
      }
    }
  }
  while(cin >> s && s != "0"){
    string str="";
    REP(i,1,s.size()){
      if(i % 2){
        str += s[i];
      }
      else{
        str += s[i];
        cola[i/2-1] = hexToUInt(str) ;
        str.clear();
      }
    }
    int mi = inf;
    int suf = 0;
    rep(i,8){
      int d = pow((cola[0] - colb[i][0]),2) + pow((cola[1] - colb[i][1]),2)+pow((cola[2] - colb[i][2]),2);
      if(mi > d){
        suf = i;
        mi = d;
      }
    }
    cout << name[suf]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cmath>

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[][4] = {{{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[9] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

int main()
{
	solve();
	return(0);
}