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 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[9][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);
}

C++: #include<iostream>
#include<map>
#include<math.h>

using namespace std;

map<int, int> MR;
map<int, int> MG;
map<int, int> MB;

void make(){
  MR[0] = 0;
  MG[0] = 0;
  MB[0] = 0;
  MR[1] = 0;
  MG[1] = 0;
  MB[1] = 255;
  MR[2] = 0;
  MG[2] = 255;
  MB[2] = 0;
  MR[3] = 0;
  MG[3] = 255;
  MB[3] = 255;
  MR[4] = 255;
  MG[4] = 0;
  MB[4] = 0;
  MR[5] = 255;
  MG[5] = 0;
  MB[5] = 255;
  MR[6] = 255;
  MG[6] = 255;
  MB[6] = 0;
  MR[7] = 255;
  MG[7] = 255;
  MB[7] = 255;
}

int main(){

  make();

  char in[2];
  int status = 0;

  while(cin >> in[0]){
    if(in[0] == '0') break;

    int r, g, b;

    for(int i = 0; i < 3; i++){
      
      cin >> in[0] >> in[1];

      for(int j = 0; j <= 1; j++){
	if(in[j] == 'a') in[j] -= 39;
	if(in[j] == 'b') in[j] -= 39;
	if(in[j] == 'c') in[j] -= 39;
	if(in[j] == 'd') in[j] -= 39;
	if(in[j] == 'e') in[j] -= 39;
	if(in[j] == 'f') in[j] -= 39;
      }

      if(i == 0) r = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 1) g = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 2) b = (in[0] - 48) * 16 + (in[1] - 48);
    }

    double d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = sqrt((r - MR[j])*(r - MR[j])+(g - MG[j])*(g - MG[j])+(b - MB[j])*(b - MB[j]));
      if(j == 0 || min > d){
	min = d;
	then = j;
      }
    }

    if(then == 0) cout << "black" <<endl;
    if(then == 1) cout << "blue" <<endl;
    if(then == 2) cout << "lime" <<endl;
    if(then == 3) cout << "aqua" <<endl;
    if(then == 4) cout << "red" <<endl;
    if(then == 5) cout << "fuchsia" <<endl;
    if(then == 6) cout << "yellow" <<endl;
    if(then == 7) cout << "white" <<endl;

  }
  return 0;
}

C++: // AOJ 0176
#include<algorithm>
#include<iostream>
#include<sstream>
#include<string>
#include<utility>

typedef std::pair<int, int> P;

const int INF = 1 << 30;

const int r[8] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff },
		  g[8] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff },
		  b[8] = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff };

const std::string cols[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

int sqr( int x )
{
	return x * x;
}

int main()
{
	std::string s;
	while( std::cin >> s, s != "0" )
	{
		std::string t;
		for( int i = 1; i != s.size(); ++i )
		{
			t += s[i];
			if( i % 2 == 0 && i < 6 )
			{
				t += ' ';
			}
		}

		std::istringstream iss( t );
		int R, G, B;
		iss >> std::hex >> R >> G >> B;

		P ans( INF, INF );
		for( int i = 0; i != 8; ++i )
		{
			int d = sqr( R - r[i] ) + sqr( G - g[i] ) + sqr( B - b[i] );
			ans = std::min( ans, P( d, i ) );
		}

		std::cout << cols[ans.second] << std::endl;
	}

	return 0;
}

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

const int INF = 10000000;

int base16(char c) {
  if( 'a' <= c ) return c-'a'+10;
  else return c-'0';
}

int main() {

  string s;

  int coltabel[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 nametable[8] = { "black", "blue", "lime", "aqua",
			 "red", "fuchsia", "yellow", "white" };

  while(true) {

    cin>>s;
    if( s=="0" ) break;

    int r,g,b;
    r = base16(s[1])*16+base16(s[2]);
    g = base16(s[3])*16+base16(s[4]);
    b = base16(s[5])*16+base16(s[6]);

    int res,tmp=INF,t;

    for(int i=0; i<8; i++) {
      if( ( t = (r-coltabel[i][0])*(r-coltabel[i][0])
	  + (g-coltabel[i][1])*(g-coltabel[i][1])
	  + (b-coltabel[i][2])*(b-coltabel[i][2]) )
	  < tmp ) {
	//cout<<t<<" "<<i<<endl;
	res = i;
	tmp = t;
      }
    }

    cout<<nametable[res]<<endl;
  }
}

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

int R,G,B;
void solve() {
  string color[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  int icolor[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 nearest=0,dist,mindist=1000000;
  for(int i=0;i<8;i++) {
    dist =  (R-icolor[i][0])*(R-icolor[i][0]) + (G-icolor[i][1])*(G-icolor[i][1]) + (B-icolor[i][2])*(B-icolor[i][2]);
    if(dist < mindist) {
      mindist = dist;
      nearest = i;
    }
  }
  cout << color[nearest] << endl;
}

int main() {
  string str;
  while(getline(cin,str)) {
    if(str == "0") break;
    R = strtol(str.substr(1,2).c_str(),NULL,16);
    G = strtol(str.substr(3,2).c_str(),NULL,16);
    B = strtol(str.substr(5,2).c_str(),NULL,16);
    solve();
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>


using namespace std;

int a[10][4]={{0,0,0,0},{0,0,265},{0,265,0},{0,265,265},{265,0,0},{265,0,265},{265,265,0},{265,265,265}};
int main(){


	
	while(1){
	string p;
	cin>>p;if(p=="0")return 0;

	int Y[15]={};
	for(int i=1;i<p.size();i++){
		if(p[i]>='0'&&p[i]<='9')Y[i]=p[i]-'0';
		else {Y[i]=10;Y[i]+=p[i]-'a';
		}
	}
	int X[5]={};
	for(int i=0;i<3;i++){
		X[i]+=16*Y[2*i+1];
		X[i]+=Y[2*i+2];
	}
	double ans=0,Bst=9999;
	int k=0;
	double c0=X[0],c1=X[1],c2=X[2];
	for(int i=0;i<8;i++){
		double A=a[i][0]-c0,B=a[i][1]-c1,C=a[i][2]-c2;
		
		ans=sqrt(A*A+B*B+C*C);
		if(ans<Bst){Bst=ans;k=i;}
	}
	if(k==7)cout<<"white"<<endl;
	else if(k==6)cout<<"yellow"<<endl;
	else if(k==5)cout<<"fuchsia"<<endl;
	else if(k==4)cout<<"red"<<endl;
	else if(k==3)cout<<"aqua"<<endl;
	else if(k==2)cout<<"lime"<<endl;
	else if(k==1)cout<<"blue"<<endl;
	else if(k==0)cout<<"black"<<endl;
	}
	}