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>
#include<cmath>
#include<string>
#include<cctype>
#define sq(a) ((a)*(a))
using namespace std;
int dist(int R, int G, int B, int rR, int rG, int rB){
	return sq(R-rR) + sq(G-rG) + sq(B-rB);
}
string judge(int R, int G, int B ){
	int min_dist = 1<<30;
	string color;

	int r;
	
	r = dist( R, G, B, 0, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "black";
	}
	r = dist( R, G, B, 0, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "blue";
	}
	r = dist( R, G, B, 0, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "lime";
	}
	r = dist( R, G, B, 0, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "aqua";
	}
	r = dist( R, G, B, 0xFF, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "red";
	}
	r = dist( R, G, B, 0xFF, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "fuchsia";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "yellow";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "white";
	}
	return color;
}

int main(){
	while( true ){
		int R;
		int G;
		int B;
		char c;
		string s;
		scanf("%c", &c);
		if( c=='0')break;
		scanf("%2x%2x%2x", &R, &G, &B);
		getline(cin,s);
		cout << judge(R,G,B) << endl;
	}
	return 0;
}

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

class Color
{
public:
  Color(int r, int g, int b);
  int get_R();
  int get_G();
  int get_B();
  string near_color();

private:
  int m_R;
  int m_G;
  int m_B;
  double diff( Color col );

  static Color black;
  static Color blue;
  static Color lime;
  static Color aqua;
  static Color red;
  static Color fuchsia;
  static Color yellow;
  static Color white;
};

Color Color::black(   0x00, 0x00, 0x00 );
Color Color::blue(    0x00, 0x00, 0xff );
Color Color::lime(    0x00, 0xff, 0x00 );
Color Color::aqua(    0x00, 0xff, 0xff );
Color Color::red(     0xff, 0x00, 0x00 );
Color Color::fuchsia( 0xff, 0x00, 0xff );
Color Color::yellow(  0xff, 0xff, 0x00 );
Color Color::white(   0xff, 0xff, 0xff );

Color::Color(int r, int g, int b)
{
  m_R = r;
  m_G = g;
  m_B = b;
}

int Color::get_R()
{
  return m_R;
}

int Color::get_G()
{
  return m_G;
}

int Color::get_B()
{
  return m_B;
}

double Color::diff( Color col )
{
  return sqrt( pow(m_R - col.get_R(), 2) + pow(m_G - col.get_G(), 2) + pow(m_B - col.get_B(), 2) );
}

string Color::near_color()
{
  struct Color_name
  {
    string name;
    Color color;
  };
  Color_name colors[8] = {
    "black", black,
    "blue", blue,
    "lime", lime,
    "aqua", aqua,
    "red", red,
    "fuchsia", fuchsia,
    "yellow", yellow,
    "white", white,
  };
  Color_name min = colors[0];
  for (int i=1; i<8; i++)
  {
    if ( diff(colors[i].color) < diff(min.color) )
    {
      min = colors[i];
    }
  }
  return min.name;
}

int main()
{
  while(true)
  {
    string color;
    getline(cin, color);
    if ( color == "0" ) return 0;

    int r = stoi( color.substr(1, 2), 0, 16 );
    int g = stoi( color.substr(3, 2), 0, 16 );
    int b = stoi( color.substr(5, 2), 0, 16 );
    Color c(r, g, b);
    cout << c.near_color() << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  int n;
  string name;
};

const int c[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff}, {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};

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

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = sqrt((c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b));
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}

C++: #include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){

	string inp;
	string base = ("0123456789abcdef" );
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[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 r, g, b;
	int ans;
	double ansnum;

	while (1){

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

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0);
		for (int i = 1; i < 8; i++){
			if (ansnum>pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0)){
				ans = i;
				ansnum = pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0);
			}
		}

		cout << scol[ans] << endl;

	}
}

C++: //何を何に変換するかが大事だと思う。(良問)
#include<stdio.h>
#define INF 100000000

char *color[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int X[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(){
	char c[3];
	int rgb[3];
	int index;
	int mini;
	
	while( scanf("%c",c) ){
		if( c[0] == '\n' || c[0] == '\r' )
			continue;			
		if( c[0] == '0' )
			break;
			
		for( int i = 0;i < 3;i++ ){
			int num = 0;
			scanf("%c%c",c,c+1);
			if( c[0] <= '9' )
				num += (c[0]-'0')*16;
			else
				num += (c[0]-'a'+10)*16;
			if( c[1] <= '9' )
				num += (c[1]-'0');
			else
				num += (c[1]-'a'+10);
			rgb[i] = num;
		}
		
		mini = INF;
		
		for( int i = 0;i < 8;i++ ){
			int num = 0;
			for( int j = 0;j < 3;j++ ){
				num += (X[i][j]-rgb[j])*(X[i][j]-rgb[j]);
			}
			if( mini > num ){
				index = i;
				mini = num;
			}
		}
		printf("%s\n",color[index]);
	}
	return 0;
}