Problem:
何色？
ウェブデザイナーを目指す太郎君はただいま修行中。事務所の先輩から「このページの背景色は#ffe085で」と、ウェブデザイン特有の色番号で指示されるのですが、それがどんな色かパッと思い浮かべることができません。
この色番号は光の三原色である赤、緑、青それぞれの強さを表わしています。具体的には2 桁の 16 進数を3 つ組み合わせたもので、色番号を“#RGB”とするとき、R は赤の強さ、G は緑の強さ、は青の強さを表します。それぞれ 00 から ff までの値になります。
色番号にまだ不慣れな太郎君のために、色番号を入力とし、色の表の中からもっとも近い色の名前
を出力するプログラムを作成してください。使用する色の表は以下の通りです。
色の名前
赤の強さ
緑の強さ
青の強さ
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
「もっとも近い色」とは、以下のように定義します。与えられた色番号での赤、緑、青の強さをそれぞれ
R
、
G
、
B
とし、表の
k
番目の色の赤、緑、青の強さをそれぞれ
R
k
、
G
k
、
B
k
とするとき、次の式で計算する
d
k
の値が最も小さい色がもっとも近い色とします。
なお、
d
k
の値が同じになる色が複数存在する場合は表の中でより上にある色がもっとも近い色になり
ます。
Input
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットとして、色番号を表す文字列が、
#
RGB
形式で１行に与えられます。
データセットの数は 1000 を超えません。
Output
データセット毎に最も近い色の名前を１行に出力します。
Sample Input
#ffe085
#787878
#decade
#ff55ff
0
Output for the Sample Input
white
black
white
fuchsia

Submitted solutions:

code_snippet: #include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int btoh(string s){
    if(s.size()!=2)cout<<"error"<<endl;
    int ret=0;
    if('0'<=s[1]&&s[1]<='9')ret+=(s[1]-'0');
    else{
        ret+=10+(int)(s[1]-'a');
    }
    if('0'<=s[0]&&s[0]<='9')ret+=(s[0]-'0')*16;
    else{
        ret+=(10+(int)(s[0]-'a'))*16;
    }
    return ret;
}

double solve(string a,string b,string c,string d,string e,string f){
    int x,y,z;
//    cout<<btoh(a)<<" "<<btoh(b)<<" "<<btoh(c)<<" "<<btoh(d)<<" "<<btoh(e)<<" "<<btoh(f)<<endl;
    x=(btoh(a)-btoh(d)) * (btoh(a)-btoh(d));
    y=(btoh(b)-btoh(e)) * (btoh(b)-btoh(e));
    z=(btoh(c)-btoh(f)) * (btoh(c)-btoh(f));
    
    return sqrt(x+y+z);
}

int main(){
//    string color = {"black","blue",}
    string s;
    while(cin>>s){
        if(s=="0")break;
        string a,b,c;
        a=s.substr(1,2);
        b=s.substr(3,2);
        c=s.substr(5,2);
        string ans="";
        double d=INF;
        
        double t=solve(a,b,c,"00","00","00");
        if(t<d){
            d=t;
            ans="black";
        }
        
        t=solve(a,b,c,"00","00","ff");
        if(t<d){
            d=t;
            ans="blue";
        }
        
        t=solve(a,b,c,"00","ff","00");
        if(t<d){
            d=t;
            ans="lime";
        }
        
        t=solve(a,b,c,"00","ff","ff");
        if(t<d){
            d=t;
            ans="aqua";
        }
        
        t=solve(a,b,c,"ff","00","00");
        if(t<d){
            d=t;
            ans="red";
        }
        
        t=solve(a,b,c,"ff","00","ff");
        if(t<d){
            d=t;
            ans="fuchsia";
        }
        
        t=solve(a,b,c,"ff","ff","00");
        if(t<d){
            d=t;
            ans="yellow";
        }
        
        t=solve(a,b,c,"ff","ff","ff");
        if(t<d){
            d=t;
            ans="white";
        }
        cout<<ans<<endl;
    }
}

/*
 black	00	00	00
 blue	00	00	ff
 lime	00	ff	00
 aqua	00	ff	ff
 red	ff	00	00
 fuchsiaff	00	ff
 yellow	ff	ff	00
 white	ff	ff	ff

 */
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string strength[8] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int toi(string s){
    int ret = 0;
    rep(i, s.size()){
        string t = s.substr(i, 1);
        if('0' <= t[0] && t[0] <= '9') ret += stoi(t);
        else ret += t[0]-'a'+10;
        if(i != s.size()-1) ret *= 16;
    }
    return ret;
}

vector<int> rgb(string s){
    vi ret;
    rep(i, 3){
        string t = s.substr(i*2, 2);
        ret.pb(toi(t));
    }
    return ret;
}

int main(){
    string  s;
    while(cin >> s, s!="0"){
        s = s.substr(1);
        vi c = rgb(s);
        double m = inf;
        int ans = 0;
        rep(i, 8){
            vi d = rgb(strength[i]);
            double ret = sqrt(pow(c[0]-d[0], 2)+pow(c[1]-d[1], 2)+pow(c[2]-d[2], 2));
            if(m > ret){ans = i; m = ret;}
        }
        cout << color[ans] << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 1212
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <string>
using namespace std;

template<class T>
T sqr(T obj) {return obj * obj;}

struct color {
	string name;
	int R, G, B;

	color(string n, int r, int g, int b) {
		name = n;
		R = r;
		G = g;
		B = b;
	}
};

color color_list[] = {
	color("black", 0x00, 0x00, 0x00),
	color("blue", 0x00, 0x00, 0xff),
	color("lime", 0x00, 0xff, 0x00),
	color("aqua", 0x00, 0xff, 0xff),
	color("red", 0xff, 0x00, 0x00),
	color("fuchsia", 0xff, 0x00, 0xff),
	color("yellow", 0xff, 0xff, 0x00),
	color("white", 0xff, 0xff, 0xff),
};

int main() {
	string s;
	while(cin >> s) {
		if(s[0] == '0')
			break;

		int mind, indx;
		indx = 0;
		mind = 1e8;

		int a[3];
		for(int j = 0; j < 3; j++) {
			int tmp = 0;
			if('0' <= s[1 + 2 * j] && s[1 + 2 * j] <= '9')
				tmp += (s[1 + 2 * j] - '0') * 16;
			else
				tmp += (s[1 + 2 * j] - 'a' + 10) * 16;

			if('0' <= s[2 + 2 * j] && s[2 + 2 * j] <= '9')
				tmp += (s[2 + 2 * j] - '0');
			else
				tmp += (s[2 + 2 * j] - 'a' + 10);
			a[j] = tmp;
		}

		for(int i = 0; i < 8; i++) {
			int d = 0;

			d += sqr(color_list[i].R - a[0]);
			d += sqr(color_list[i].G - a[1]);
			d += sqr(color_list[i].B - a[2]);
			if(d < mind) {
				indx = i;
				mind = d;
			}
		}
		cout << color_list[indx].name << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1184
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

double x(string s) {
  double a=1,ans=0;
  rrep(i,2) {
    if(isdigit(s[i])) ans+=(int)(s[i]-'0')*a;
    else ans+=((int)(s[i]-'a')+10)*a;
    a*=16;
  }
  return ans;
}

int main() {
  double d[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 c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  string s;
  while(cin >> s && s!="0") {
    int ans=0;
    double min=MAX;
    double z[3];
    s=s.substr(1);
    rep(i,3) z[i]=x(s.substr(i*2,2));
    rep(i,8) {
      double v=sqrt((z[0]-d[i][0])*(z[0]-d[i][0])+(z[1]-d[i][1])*(z[1]-d[i][1])+(z[2]-d[i][2])*(z[2]-d[i][2]));
      if(v<min) {
	ans=i;
	min=v;
      }
    }
    pr(c[ans]);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1188
final_rank: 4

code_snippet: #include <iostream>
#include <string>
#include <climits>
using namespace std;

int conv(char a) {
  if (a >= '0' && a <= '9') {
    return a - '0';
  } else {
    return a - 'a' + 10;
  }
}

int conv(char a, char b) {
  return conv(a)*16 + conv(b);
}

int main() {
  string str;
  int c[3], d, m, ans;
  int cc[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 char *label[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

  while (1) {
    cin >> str;
    if (str == "0") break;
    for (int i=0; i<3; i++) {
      c[i] = conv(str.at(2*i+1), str.at(2*i+2));
    }
    m = INT_MAX;
    ans = -1;
    for (int i=0; i<8; i++) {
      d = 0;
      for (int j=0; j<3; j++) {
        d += (c[j]-cc[i][j])*(c[j]-cc[i][j]);
      }
      if (m > d) {
        m = d;
        ans = i;
      }
    }
    cout << label[ans] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1180
final_rank: 2

code_snippet: #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;
}
accuracy: 1
time_ms: 10
memory_kb: 1188
final_rank: 4

code_snippet: #include <iostream>

using namespace std;

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

int to_decimal(string s) 
{
    int d[2];
    int ret = 0;

    for (int i = 0; i < 2; i++) {
        if ('a' <= s[i] && s[i] <= 'f') 
            d[i] = s[i] - 'a' + 10;
        else
            d[i] = s[i] - '0';
    }

    return d[0] * 16 + d[1];
}

int main()
{
    string inp;

    while (cin >> inp, inp != "0") {
        int r, g, b;
        int d = 200000;
        int idx = 0;
        
        r = to_decimal(inp.substr(1, 2));
        g = to_decimal(inp.substr(3, 2));
        b = to_decimal(inp.substr(5, 2));

        for (int i = 0; i < 8; i++) {
            int tmp;
            tmp = (r - rgb[i][0]) * (r - rgb[i][0]) + 
                (g - rgb[i][1]) * (g - rgb[i][1]) +
                (b - rgb[i][2]) * (b - rgb[i][2]);

            if (tmp < d) {
                d = tmp;
                idx = i;
            }
        }
        cout << name[idx] << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1188
final_rank: 4

code_snippet: #include <iostream>
#include <string>
#include <cctype>

using namespace std;

int pow(int x, int n) {
  int ans = 1;
  for(int i = 0; i < n; i++) {
    ans *= x;
  }
  return ans;
}

int charToInt(char c) {
  return (int)c - (int)'0';
}

int _16to10(char c) {
  int ans = charToInt(c);
  if(ans >= 0 && ans <= 9) return ans;
  else return (int)tolower(c) - (int)'a' + 10;
}

int _16to10(string str) {
  int ans = 0;
  for(int i = 0; i < str.length(); i++) {
    ans += _16to10(str[i])*pow(16, str.length()-i-1);
  }
  return ans;
}

int d2(string a, string b) {
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    int p = i*2;
    ans += pow(_16to10(a.substr(p,2))-_16to10(b.substr(p,2)), 2);
  }
  return ans;
}

int main() {
  string colors[8][2] = {{"black", "000000"},
			 {"blue", "0000ff"},
			 {"lime", "00ff00"},
			 {"aqua", "00ffff"},
			 {"red", "ff0000"},
			 {"fuchsia", "ff00ff"},
			 {"yellow", "ffff00"},
			 {"white", "ffffff"}};
  while(1) {
    string str;
    cin >> str;
    if(str == "0") break;

    int min = 999999;
    int k;
    for(int i = 0; i < 8; i++) {
      int temp = d2(str.substr(1, 6), colors[i][1]);
      if(temp < min) {
	min = temp;
	k = i;
      }
    }
    cout << colors[k][0] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int h(string s){
	int ret = 0;
	int src = 1;
	for(int i=s.length()-1;i>=0;i--){
		ret += (s[i]>'9'?s[i]-'a'+10:s[i]-'0')*src;
		src *= 16;
	}
	return ret;
}

double f(string a,string b){	
	string tr,tg,tb;
	string tr2,tg2,tb2;
	tr = a.substr(1,2);
	tg = a.substr(3,2);
	tb = a.substr(5,2);
	tr2 = b.substr(1,2);
	tg2 = b.substr(3,2);
	tb2 = b.substr(5,2);
	return sqrt(
		(h(tr)-h(tr2))*(h(tr)-h(tr2)) +
		(h(tg)-h(tg2))*(h(tg)-h(tg2)) +
		(h(tb)-h(tb2))*(h(tb)-h(tb2))
	);
}
int main(){
	double MIN;
	string ret;
	
	string rgb;
	while(cin >> rgb && rgb[0] != '0'){
		MIN = (1<<21);
		if(MIN >     f(rgb,"#000000")){
			MIN = f(rgb,"#000000");
			ret = "black";
		}
		if(MIN >     f(rgb,"#0000ff")){
			MIN = f(rgb,"#0000ff");
			ret = "blue";
		}
		if(MIN >     f(rgb,"#00ff00")){
			MIN = f(rgb,"#00ff00");
			ret = "lime";
		}
		if(MIN >     f(rgb,"#00ffff")){
			MIN = f(rgb,"#00ffff");
			ret = "aqua";
		}
		if(MIN >     f(rgb,"#ff0000")){
			MIN = f(rgb,"#ff0000");
			ret = "red";
		}
		if(MIN >     f(rgb,"#ff00ff")){
			MIN = f(rgb,"#ff00ff");
			ret = "fuchsia";
		}
		if(MIN >     f(rgb,"#ffff00")){
			MIN = f(rgb,"#ffff00");
			ret = "yellow";
		}
		if(MIN >     f(rgb,"#ffffff")){
			MIN = f(rgb,"#ffffff");
			ret = "white";
		}
		cout << ret << endl;

	}
}
accuracy: 1
time_ms: 30
memory_kb: 908
final_rank: 9