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<map>
using namespace std;
int main() {
	map <char, int>b;
	b.insert(map<char, int>::value_type('0', 0));
	b.insert(map<char, int>::value_type('1', 1));
	b.insert(map<char, int>::value_type('2', 2));
	b.insert(map<char, int>::value_type('3', 3));
	b.insert(map<char, int>::value_type('4', 4));
	b.insert(map<char, int>::value_type('5', 5));
	b.insert(map<char, int>::value_type('6', 6));
	b.insert(map<char, int>::value_type('7', 7));
	b.insert(map<char, int>::value_type('8', 8));
	b.insert(map<char, int>::value_type('9', 9));
	b.insert(map<char, int>::value_type('a', 10));
	b.insert(map<char, int>::value_type('b', 11));
	b.insert(map<char, int>::value_type('c', 12));
	b.insert(map<char, int>::value_type('d', 13));
	b.insert(map<char, int>::value_type('e', 14));
	b.insert(map<char, int>::value_type('f', 15));
	string d[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int e[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 a;
	while (cin >> a&&a != "0") {
		int sa = 10000, t[3];
		string iro;
		for (int i = 1; i < 7; i += 2) {
			char f = a[i], g = a[i + 1];
			t[(i - 1) / 2] = b[f]*16 + b[g];
		}
		for (int i = 7; i >= 0; i--) {
			int h = sqrt(pow((e[i][0] - t[0]), 2) + pow((e[i][1] - t[1]), 2) + pow((e[i][2] - t[2]), 2));
			if (h <= sa) {
				sa = h;
				iro = d[i];
			}
		}
		cout << iro << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++)sixteen['a'-'0'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=(num[j]-colornum[i][j])*(num[j]-colornum[i][j]);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s){
	int k=1,res=0;
	for(int i=s.size()-1;i>=0;i--){
		if('0'<=s[i]&&s[i]<='9'){
			res+=k*(s[i]-'0');
		}else{
			res+=k*(s[i]-'a'+10);
		}
		k*=16;
	}
	return res;
}

int main(){
	string ans[2][2][2];
	ans[0][0][0]="black";
	ans[0][0][1]="blue";
	ans[0][1][0]="lime";
	ans[0][1][1]="aqua";
	ans[1][0][0]="red";
	ans[1][0][1]="fuchsia";
	ans[1][1][0]="yellow";
	ans[1][1][1]="white";
	char s[8];
	while(scanf("%s",s)&&s[0]!='0'){
		int a,b,c,dat[3];
		for(int i=1;i<6;i+=2){
			string tmp;int ans[3];
			tmp.assign(s,i,2);
			int d=to_int(tmp);
			if(d<=(to_int("ff")-d))ans[i/2]=0;
			else ans[i/2]=1;
		}
		cout<<ans[dat[0]][dat[1]][dat[2]]<<endl;
	}
}

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

int main() {
	while(1){
		string str; cin >> str ; if(str=="0") break;
		int Color[3]={0};
		for(int i=1;i<str.size();i+=2){
			char ch[2];
			ch[0]=str[i],ch[1]=str[i+1];
			int tmp=0;
			for(int j=0;j<2;j++){
				if('0'<=ch[j] && ch[j]<='9') tmp+=(ch[j]-'0');
				else if('a'<=ch[j] && ch[j]<='f') tmp+=(ch[j]-'a')+10;
				if(j==0) tmp*=16;
			}
			Color[(int)( (i-1)/2 )] = tmp;
		}
		int samp[8][3]; memset(samp,0,sizeof(samp));
		samp[1][2]=samp[2][1]=samp[3][1]=samp[3][2]=255;
		samp[4][0]=samp[5][0]=samp[5][2]=samp[6][0]=samp[6][1]
		=samp[7][0]=samp[7][1]=samp[7][2]=255;
		string tmp[8];
		tmp[0]="black", tmp[1]="blue", tmp[2]="lime", tmp[3]="aqua",
		tmp[4]="red", tmp[5]="fuchsia", tmp[6]="yellow", tmp[7]="white";
		long MIN=0; for(int i=0;i<3;i++) MIN+=Color[i]*Color[i];
		string ans="black";
		for(int i=1;i<8;i++){
			long TMP=0;
			for(int j=0;j<3;j++) TMP+=(Color[j]-samp[i][j])*(Color[j]-samp[i][j]);
			if(TMP<MIN) MIN=TMP, ans=tmp[i];
		}
		cout << ans << '\n' ;
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
char c[8];
char d[3];
char ret[8][10]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int R[]={0,0,0,0,255,255,255,255};
int G[]={0,0,255,255,0,0,255,255};
int B[]={0,255,0,255,0,255,0,255};
int main(){
	while(1){
		scanf("%s",c);
		if(c[0]!='#')return 0;
		d[0]=c[1];
		d[1]=c[2];
		d[2]='\0';
		int r=strtol(d,NULL,16);
		d[0]=c[3];
		d[1]=c[4];
		int g=strtol(d,NULL,16);
		d[0]=c[5];
		d[1]=c[6];
		int b=strtol(d,NULL,16);
		int min=99999999;
		int at=0;
		for(int i=0;i<8;i++)
			if(min>(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i])){
				min=(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i]);
				at=i;
			}
		
		printf("%s\n",ret[at]);
	}
}

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

using namespace std;

void DevideColor(string, int&, int&, int&);
int Atoi16(char);
double Calculate(int, int, int, int, int, int);

int main(){
  int i, Red, Green, Blue;
  double min, font[8];
  string Color, StrongColor;
  string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia","yellow", "white"};

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

    DevideColor(Color, Red, Green, Blue);

    font[0] = Calculate(Red, Green, Blue, 0, 0, 0);
    font[1] = Calculate(Red, Green, Blue, 0, 0, 225);
    font[2] = Calculate(Red, Green, Blue, 0, 225, 0);
    font[3] = Calculate(Red, Green, Blue, 0, 225, 225);
    font[4] = Calculate(Red, Green, Blue, 225, 0, 0);
    font[5] = Calculate(Red, Green, Blue, 225, 0, 225);
    font[6] = Calculate(Red, Green, Blue, 225, 225, 0);
    font[7] = Calculate(Red, Green, Blue, 225, 225, 225);

    min = font[0];
    StrongColor = color[0];

    for(i=1; i<8; ++i){
      if(font[i] < min){
        min = font[i];
        StrongColor = color[i];
      }
    }

    cout << StrongColor << endl;
  }

  return 0;

}

void DevideColor(string s, int& r, int& g, int& b){
  string R, G, B;
  copy(s.begin()+1, s.begin()+3, back_inserter(R));
  copy(s.begin()+3, s.begin()+5, back_inserter(G));
  copy(s.begin()+5, s.end(), back_inserter(B));
  r = Atoi16(R[0])*16 + Atoi16(R[1]);
  g = Atoi16(G[0])*16 + Atoi16(G[1]);
  b = Atoi16(B[0])*16 + Atoi16(B[1]);
}

int Atoi16(char c){
  int x;
  if(c >= '0' && c <= '9')
    x = c - 48;
  else
    x = c - 87;
  return x;
}

double Calculate(int r, int g, int b, int _r, int _g, int _b){
  int R, G, B;
  R = r - _r;
  G = g - _g;
  B = b - _b;
  return sqrt(R*R + G*G + B*B);
}