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>
using namespace std;
int main(){
long i,j,k;
string s,c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
while(cin>>s){
if(s=="0")break;
k=0;
i=s[1]-48;if(s[1]>64)i-=7;
j=s[2]-48;if(s[2]>64)j-=7;
if(i*16+j>=128)k+=4;
i=s[3]-48;if(s[3]>64)i-=7;
j=s[4]-48;if(s[4]>64)j-=7;
if(i*16+j>=128)k+=2;
i=s[5]-48;if(s[5]>64)i-=7;
j=s[6]-48;if(s[6]>64)j-=7;
if(i*16+j>=128)k++;
cout<<c[k]<<endl;
}
return 0;
}

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

double dis(int r1,int r2,int g1,int g2,int b1,int b2){
  return sqrt( (r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2) );
}

int main(){
  string color,ans;
  int r,g,b;
  double dmin,tmp;

  while(1){
    cin >> color;
    if(color=="0")break;

    r = 0;
    if(color[1]-'0' < 10)r += 16*(color[1]-'0');
    else r += 16 * (color[1]-'a'+10);
    if(color[2]-'0' < 10)r += color[2]-'0';
    else r += color[2]-'a'+10;
    g = 0;
    if(color[3]-'0' < 10)g += 16*(color[3]-'0');
    else g += 16 * (color[3]-'a'+10);
    if(color[4]-'0' < 10)g += color[4]-'0';
    else g += color[4]-'a'+10;
    b = 0;
    if(color[5]-'0' < 10)b += 16*(color[5]-'0');
    else b += 16 * (color[5]-'a'+10);
    if(color[6]-'0' < 10)b += color[6]-'0';
    else b += color[6]-'a'+10;

    dmin = 510;
    tmp = dis(r,0,g,0,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "black";
    }
    tmp = dis(r,0,g,0,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "blue";
    }
    tmp = dis(r,0,g,255,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "lime";
    }
    tmp = dis(r,0,g,255,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "aqua";
    }
    tmp = dis(r,255,g,0,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "red";
    }
    tmp = dis(r,255,g,0,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "fuchsia";
    }
    tmp = dis(r,255,g,255,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "yellow";
    }
    tmp = dis(r,255,g,255,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "white";
    }

    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

const int INF = 1e9;
typedef long long ll;

struct Color{
  string name;
  int R, G, B;
};

Color list[8];

void init(){
  list[0].name = "black";   list[0].R = 0x00; list[0].G = 0x00; list[0].B = 0x00;
  list[1].name = "blue";    list[1].R = 0x00; list[1].G = 0x00; list[1].B = 0xff;
  list[2].name = "lime";    list[2].R = 0x00; list[2].G = 0xff; list[2].B = 0x00;
  list[3].name = "aqua";    list[3].R = 0x00; list[3].G = 0xff; list[3].B = 0xff;
  list[4].name = "red";     list[4].R = 0xff; list[4].G = 0x00; list[4].B = 0x00;
  list[5].name = "fuchsia"; list[5].R = 0xff; list[5].G = 0x00; list[5].B = 0xff;
  list[6].name = "yellow";  list[6].R = 0xff; list[6].G = 0xff; list[6].B = 0x00;
  list[7].name = "white";   list[7].R = 0xff; list[7].G = 0xff; list[7].B = 0xff;
}

int main(void){
  init();
  string colorcode;
  while(cin >> colorcode && colorcode != "0"){
    int r = stoi(string(colorcode, 1, 2), nullptr, 16);
    int g = stoi(string(colorcode, 3, 2), nullptr, 16);
    int b = stoi(string(colorcode, 5, 2), nullptr, 16);
    int n, mind = INF;
    for(int i = 0; i < 8; i++){
      int d = (r - list[i].R) * (r - list[i].R) + (g - list[i].G) * (g - list[i].G) + (b - list[i].B) * (b - list[i].B);
      if(d < mind){
        mind = d;
        n = i;
      }
    }
    cout << list[n].name << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  map<char,int>m;
  m['a']=10;
  m['b']=11;
  m['c']=12;
  m['d']=13;
  m['e']=14;
  m['f']=15;
  int col[8][3];
  col[0][0]=0;col[0][1]=0;col[0][2]=0;
  col[1][0]=0;col[1][1]=0;col[1][2]=255;
  col[2][0]=0;col[2][1]=255;col[2][2]=0;
  col[3][0]=0;col[3][1]=255;col[3][2]=255;
  col[4][0]=255;col[4][1]=0;col[4][2]=0;
  col[5][0]=255;col[5][1]=0;col[5][2]=255;
  col[6][0]=255;col[6][1]=255;col[6][2]=0;
  col[7][0]=255;col[7][1]=255;col[7][2]=255;
  while(cin>>s,s!="0"){
    int a,b,c,a1,a2;
    if(isdigit(s[1]))a1=s[1]-'0';
    else a1=m[s[1]];
    if(isdigit(s[2]))a2=s[2]-'0';
    else a2=m[s[2]];
    a=a1*16+a2;
    if(isdigit(s[3]))a1=s[3]-'0';
    else a1=m[s[3]];
    if(isdigit(s[4]))a2=s[4]-'0';
    else a2=m[s[4]];
    b=a1*16+a2;
    if(isdigit(s[5]))a1=s[5]-'0';
    else a1=m[s[5]];
    if(isdigit(s[6]))a2=s[6]-'0';
    else a2=m[s[6]];
    c=a1*16+a2;
    int p,ss=INT_MAX;
    for(int i=0;i<8;i++){
      int x=(col[i][0]-a)*(col[i][0]-a)+
            (col[i][1]-b)*(col[i][1]-b)+
            (col[i][2]-c)*(col[i][2]-c);
      if(x<ss){
        ss=x;
        p=i;
      }
    }
    if(p==0)cout<<"black"<<endl;
    if(p==1)cout<<"blue"<<endl;
    if(p==2)cout<<"lime"<<endl;
    if(p==3)cout<<"aqua"<<endl;
    if(p==4)cout<<"red"<<endl;
    if(p==5)cout<<"fuchsia"<<endl;
    if(p==6)cout<<"yellow"<<endl;
    if(p==7)cout<<"white"<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int HtoD(char c){
	if('0'<=c&&c<='9')return c-'0';
	if('A'<=c&&c<='F')return c-'A'+10;
	if('a'<=c&&c<='f')return c-'a'+10;
	return 0;
}
int main(){
	const int BCOL[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}};
	const string BCOLN[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	string s;
	while(cin>>s){
		if(s[0]=='0')break;
		int r=(HtoD(s[1])<<4)+HtoD(s[2]),g=(HtoD(s[3])<<4)+HtoD(s[4]),b=(HtoD(s[5])<<4)+HtoD(s[6]);
		int mind=195075;
		int outn=0;
		for(int i=7;i>=0;--i){
			int d = (r-BCOL[i][0])*(r-BCOL[i][0])+(g-BCOL[i][1])*(g-BCOL[i][1])+(b-BCOL[i][2])*(b-BCOL[i][2]);
			if(d<=mind){
				mind = d;
				outn = i;
			}
		}
		cout<<BCOLN[outn]<<"\n";
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"} {"yellow","white"} } };
char T[9] = "89abcdef";
int a, b, c;
int main() {
	while (true) {
		a = 0; b = 0; c = 0;
		cin >> S;
		if (S == "0") { break; }
		for (int i = 0; i < 8; i++){
			if (T[i] == S[1]) {
				a = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[3]) {
				b = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[5]) {
				c = 1;
			}
		}
		cout << x[a][b][c] << endl;
	}
}