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 main(){

	int color[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}};
	double d, f, p[3];
	string str, c;

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

		d = sqrt(3 * pow(255, 2));
		for(int j=0; j<3; j++){
			if(str[2*j+1] >= '0' && str[2*j+1] <= '9') p[j] = 16 * (str[2*j+1] - '0');
			else p[j] = 16 * (10.0 + str[2*j+1] - 'a');
				
			if(str[2*j+2] >= '0' && str[2*j+2] <= '9') p[j] += str[2*j+2] - '0';
			else p[j] += 10.0 + str[2*j+2] - 'a';
		}
		
		for(int i=0; i<8; i++){
			f = sqrt(pow(p[0] - color[i][0], 2) + pow(p[1] - color[i][1], 2) + pow(p[2] - color[i][2], 2));
			if(d > f){
				d = f;
				switch(i){
					case 0: c = "black"; break;
					case 1: c = "blue"; break;
					case 2: c = "lime"; break;
					case 3: c = "aqua"; break;
					case 4: c = "red"; break;
					case 5: c = "fuchsia"; break;
					case 6: c = "yellow"; break;
					case 7: c = "white"; break;
				}
			}
		}
		
		cout << c << endl;
	}

	return 0;

}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

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

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

void search(string str) {
	string input = str.substr(1, 2) + " " + str.substr(3, 2) + " " + str.substr(5, 2);
	
	int col[3];
	sscanf(input.c_str(), "%x %x %x", &col[0], &col[1], &col[2]);
	
	int min_dst = 1L << 30, ans = -1;
	
	for_(i,0,8) {
		int dst = 0;
		
		for_(j,0,3) {
			dst += sqr(rgb[i][j] - col[j]);
		}
		
		if (min_dst > dst) {
			min_dst = dst;
			ans = i;
		}
	}
	
	cout << name[ans] << endl;
}

int main() {
	string str;
	while (cin >> str, str != "0") search(str);
}

C++: #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
  char c[10];
  int r,g,b,id;
  string str[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  while(scanf("%s",c),c[0]!='0'){
    r = g = b = 0;
    if('0'<=c[1] && c[1]<='9') r += (c[1]-'0')*16;
    else r += (c[1]-'A'+10)*16;
    if('0'<=c[2] && c[2]<='9') r += (c[2]-'0');
    else r += (c[2]-'A'+10);
    if('0'<=c[3] && c[3]<='9') g += (c[3]-'0')*16;
    else g += (c[3]-'A'+10)*16;
    if('0'<=c[4] && c[4]<='9') g += (c[4]-'0');
    else g += (c[4]-'A'+10);
    if('0'<=c[5] && c[5]<='9') b += (c[5]-'0')*16;
    else b += (c[5]-'A'+10)*16;
    if('0'<=c[6] && c[6]<='9') b += (c[6]-'0');
    else b += (c[6]-'A'+10);
    id = 0;
    if(r >=123) id += 4;
    if(g >=123) id += 2;
    if(b >=123) id += 1;
    cout << str[id] << endl;
  }
  return(0);
}

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

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
int stoi(char c){
  if('0' <= c && c <= '9')
    return c - '0';
  return c - 'a' + 10;
}

int pow(int n){
  return n * n;
}

int main(void){
  string s;
  string ans[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 num[8];
  int cnt = 0;
  rep(i,8)num[i] = i * 255;     
  while(cin>>s){
    if(s == "0")break;
    int in[3];
    in[0] = stoi(s[1]) * 16 + stoi(s[2]);
    in[1] = stoi(s[3]) * 16 + stoi(s[4]);
    in[2] = stoi(s[5]) * 16 + stoi(s[6]);
    //rep(i,3)cout<<in[i]<<endl;
    int index = 0;
    unsigned long long diff = 100000000;
    rep(i,8){

      int box[3];
      rep(j,3){
	box[j] = (i>>(2-j))%2*255;
      }
      
     
      unsigned long long int calc = 0;
      rep(j,3)calc += pow(in[j] - box[j]);
     	
      if(calc < diff){
	diff = calc;
	index = i;
      }
    }
    cout<<ans[index]<<endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	char l[6];
	string s;
	while (cin >> s) {
		for (int i = 0; i < 6; i++) {
			l[i] = s[i + 1];
		}
		int r, g, b;
		int z[6];

		for (int i = 0; i < 6; i++) {
			if (l[i] == '0') {
				z[i] = 0;
			}
			else if (l[i] == '1') {
				z[i] = 1;
			}
			else if (l[i] == '2') {
				z[i] = 2;
			}
			else if (l[i] == '3') {
				z[i] = 3;
			}
			else if (l[i] == '4') {
				z[i] = 4;
			}
			else if (l[i] == '5') {
				z[i] = 5;
			}
			else if (l[i] == '6') {
				z[i] = 6;
			}
			else if (l[i] == '7') {
				z[i] = 7;
			}
			else if (l[i] == '8') {
				z[i] = 8;
			}
			else if (l[i] == '9') {
				z[i] = 9;
			}			
			else if (l[i] == 'a') {
				z[i] = 10;
			}
			else if (l[i] == 'b') {
				z[i] = 11;
			}
			else if (l[i] == 'c') {
				z[i] = 12;
			}
			else if (l[i] == 'd') {
				z[i] = 13;
			}
			else if (l[i] == 'e') {
				z[i] = 14;
			}
			else if (l[i] == 'f') {
				z[i] = 15;
			}
		}

		r = z[0] * 16 + z[1];
		g = z[2] * 16 + z[3];
		b = z[4] * 16 + z[5];

		
		//ff == 255;
		if (r <= 128) {
			//black,blue,lime,aqua
			if (g <= 128) {
				//black,blue
				if (b <= 128) {
					cout << "black";
				}
				else {
					cout << "blue";
				}
			}
			else {
				//lime,aqua
				if (b <= 128) {
					cout << "lime";
				}
				else {
					cout << "aqua";
				}
			}
		}
		else {
			//red,fuchsia,yellow,white
			if (g <= 128) {
				//red,fu
				if (b <= 128) {
					cout << "red";
				}
				else {
					cout << "fuchsia";
				}
			}
			else {
				if (b <= 128) {
					cout << "yellow";
				}
				else
				{
					cout << "white";
				}
			}
		}
		cout << endl;
	}

	return 0;
}

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

string str;

string t[8][4]={
  {"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 c2i(char ch){
  if('0'<=ch&&ch<='9')return ch-'0';
  return 10+ch-'a';
}

int cc2i(char ch,char ch2){
  return c2i(ch)*16+c2i(ch2);
}

int s2i(string str){
  return cc2i(str[0],str[1]);
}

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

int main(){
  int a,mini,mini_no;
  while(cin>>str){
    if(str=="0")break;
    mini=9999999;
    for(int i=0;i<8;i++){
      a=pow( cc2i(str[1],str[2]) - s2i(t[i][1]) ); 
      a+=pow(cc2i(str[3],str[4]) - s2i(t[i][2]) );
      a+=pow(cc2i(str[5],str[6]) - s2i(t[i][3]) ); 
      if(a<mini){
	mini=a;
	mini_no=i;
      }
    }
    cout<<t[mini_no][0]<<endl;
  }
  return 0;
}