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 <bits/stdc++.h>
using namespace std;

int to10(const string &s) {
  int x = 0;
  for(int i = 0; i < s.size(); ++i) {
    int d;
    if(isdigit(s[i])) d = s[i] - '0';
    else d = 10 + s[i] - 'a';
    x = x * 16 + d;
  }
  return x;
}

vector<int> conv(const string &s) {
  vector<int> res(3);
  res[0] = to10(s.substr(1,2));
  res[1] = to10(s.substr(3,2));
  res[2] = to10(s.substr(5,2));
  return res;
}

int norm(vector<int> a, vector<int> b) {
  int res = 0;
  for(int i = 0; i < 3; ++i) {
    int sub = a[i] - b[i];
    res += sub * sub;
  }
  return res;
}


int main() {
  vector<string> name;
  vector<vector<int> > v;
  name.push_back("black");
  v.push_back(conv("#000000"));
  name.push_back("blue");
  v.push_back(conv("#0000ff"));
  name.push_back("lime");
  v.push_back(conv("#00ff00"));
  name.push_back("aqua");
  v.push_back(conv("#00ffff"));
  name.push_back("red");
  v.push_back(conv("#ff0000"));
  name.push_back("fuchsia");
  v.push_back(conv("#ff00ff"));
  name.push_back("yellow");
  v.push_back(conv("#ffff00"));
  name.push_back("white");
  v.push_back(conv("#ffffff"));
  string s;
  while(cin >> s && s != "0") {
    vector<int> x = conv(s);
    int k = 0;
    for(int i = 1; i < v.size(); ++i) {
      if(norm(x, v[i]) < norm(x, v[k])) {
        k = i;
      }
    }
    cout << name[k] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

int c(char ch) {
  if(isdigit(ch)) return ch-'0';
  return ch-'a'+10;
}

int d(string s) {
  return c(s[0])*16 + c(s[1]);
}

int main() {
  
  int colR[8];
  int colG[8];
  int colB[8];
  
  colR[0] = d("00"); colG[0] = d("00"); colB[0] = d("00");
  colR[1] = d("00"); colG[1] = d("00"); colB[1] = d("ff");
  colR[2] = d("00"); colG[2] = d("ff"); colB[2] = d("00");
  colR[3] = d("00"); colG[3] = d("ff"); colB[3] = d("ff");
  colR[4] = d("ff"); colG[4] = d("00"); colB[4] = d("00");
  colR[5] = d("ff"); colG[5] = d("00"); colB[5] = d("ff");
  colR[6] = d("ff"); colG[6] = d("ff"); colB[6] = d("00");
  colR[7] = d("ff"); colG[7] = d("ff"); colB[7] = d("ff");
  
  /*
  for(int i=0; i<8; i++) {
    colR[i] = i & 1 ? 255 : 0;
    colG[i] = i & 2 ? 255 : 0;
    colB[i] = i & 4 ? 255 : 0;
  }
  */
  
  string s;
  
  while(cin >> s) {
    if(s == "0") break;
    
    s = s.substr(1);
    
    int R = d(s.substr(0, 2));
    int G = d(s.substr(2, 2));
    int B = d(s.substr(4, 2));
    
    int minD = (int)1e9;
    int id = -1;
    for(int i=0; i<8; i++) {
      if( minD > pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0) ) {
	id = i;
	minD = pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0);
      }
    }
    
    cout << colors[id] << endl;
  }
  
  return 0;
}

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

using namespace std;

string Strength[8] = {"000000","0000ff","00ff00","00ffff",
		      "ff0000","ff00ff","ffff00","ffffff"};

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

int x_t(char c){
  if(islower(c)) return 10 + (c - 'a');
  return c - '0';
}

int change(string s){
  return x_t(s[0])*16 + x_t(s[1]);
}

string solve(string R,string G,string B){
  int pos,Min = (1<<29),d;
  int r = change(R),g = change(G),b = change(B);
  string rr,gg,bb;

  for(int i = 0 ; i < 8 ; i++){
    rr = Strength[i].substr(0,2);
    gg = Strength[i].substr(2,2);
    bb = Strength[i].substr(4,2);
 
    int rk = change(rr) ,gk = change(gg) ,bk = change(bb);    
    d = sqrt((r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk));

    if(d < Min){
      Min = d;
      pos = i;
    }
  }

  return Color[pos];
}

int main(){
  string str;

  while(cin >> str ,str != "0"){
    string R,G,B;

    R = str.substr(1,2);
    G = str.substr(3,2);
    B = str.substr(5,2);

    cout << solve(R,G,B) << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,string> P;
#define INF (1<<20)

typedef struct {
  string name; // ??????
  string R; // ???
  string G; // ???
  string B; // ???
} color; // ???????§???????

color data[8]=
  {{"black","00","00","00"},
   {"blue","00","00","ff"},
   {"lime","00","ff","00"},
   {"aqua","00","ff","ff"},
   {"red","ff","00","00"},
   {"fuchsia","ff","00","ff"},
   {"yellow","ff","ff","00"},
   {"white","ff","ff","ff"}
  };

int trans(string num){
  int sum = 0;
  if(num[0] >= 'a' && num[0] <= 'f') sum = (num[0] - 'a' + 10)*16;
  else sum = (num[0] - '0')*16;
  if(num[1] >= 'a' && num[1] <= 'f') sum += (num[1] - 'a' + 10);
  else sum += (num[1] - '0');
  return sum;
}

int main(){
  string str;
  int RGB[8][3];
  for(int i=0;i<8;i++){
    RGB[i][0] = trans(data[i].R);
    RGB[i][1] = trans(data[i].G);
    RGB[i][2] = trans(data[i].B);
  }
  while(cin >> str , str!="0"){
    string red = str.substr(1,2);
    string green = str.substr(3,2);
    string blue = str.substr(5,2);
    int r = trans(red);
    int g = trans(green);
    int b = trans(blue);
    double ans = INF;
    int pos = 0;
    for(int i=0;i<8;i++){
      double tr = (r-RGB[i][0])*(r-RGB[i][0]);
      double tg = (g-RGB[i][1])*(g-RGB[i][1]);
      double tb = (b-RGB[i][2])*(b-RGB[i][2]);
      double tmp = sqrt(tr+tg+tb);
      if(ans > tmp){
	ans = tmp;
	pos = i;
      }
    }
    cout << data[pos].name << endl;
  }
}

C++: import java.util.Scanner;
import static java.lang.System.out;
class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    String name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int color[][] = {{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(true){
      String str = scan.next();
      if(str.equals("0")) break;

      int R = Integer.parseInt(str.substring(1,3),16);
      int G = Integer.parseInt(str.substring(3,5),16);
      int B = Integer.parseInt(str.substring(5,7),16);
      double min = Double.MAX_VALUE;
      int Index = 0;
      for(int i = 0 ; i < 8 ; i++){
        double near = Math.sqrt(Math.pow(R - color[i][0],2) + Math.pow(G - color[i][1],2) + Math.pow(B - color[i][2],2));
        if( near < min ){
          min = near;
          Index = i;
        }
      }
      out.println(name[Index]);
    }
  }
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#define w 15*16+15
using namespace std;
int fld[8][3]={0,0,0,0,0,w,0,w,
	0,0,w,w,w,0,0
	,w,0,w,w,w,0,w,w,w};
char* col[]={"black",
	"blue","lime","aqua",
	"red","fuchsia",
	"yellow","white"};
int main(){
	int temp,t,x,y,z,a[8],ren;
	char s[10];
	while(cin>>s,s[0]!='0'){
		temp=1000000;
		for(int i=1;i<8;i++){
			if(s[i]>'9')
			a[i-1]=9+s[i]-'a';
			else a[i-1]=s[i]-'0';
		}
		for(int i=0;i<8;i++){
			x=a[0]*16+a[1]-fld[i][0];
			y=a[2]*16+a[3]-fld[i][1];
			z=a[4]*16+a[5]-fld[i][2];
			ren=sqrt(x*x+y*y+z*z);
			if(ren<temp){
				t=i;
				temp=ren;
			}
		}cout<<col[t]<<endl;
	}
	return 0;
}