AOJ0176

問題:What Color?
16進数で入力してやるだけ。

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<cmath>
using namespace std;
double d( int a, int b )
{
	double dr = (a&0xff0000) - (b&0xff0000);
	double dg = (a&0x00ff00) - (b&0x00ff00);
	double db = (a&0x0000ff) - (b&0x0000ff);
	double dk = sqrt( dr*dr + dg*dg + db*db );
	return dk;
}
int main()
{
	map< int , string > color;
	color[ 0x000000 ] = "black";
	color[ 0x0000ff ] = "blue";
	color[ 0x00ff00 ] = "lime";
	color[ 0x00ffff ] = "aqua";
	color[ 0xff0000 ] = "red";
	color[ 0xff00ff ] = "fuchsia";
	color[ 0xffff00 ] = "yellow";
	color[ 0xffffff ] = "white";

	int in;
	while( scanf("#%x\n",&in ) == 1 )
	{
		int m = 0xffffff;
		for( map<int,string>::iterator it = color.begin(); it!=color.end(); ++it )
		{
			if( d( m,in ) > d( it->first ,in ) )m=it->first;
		}
		cout << color[m] << endl;
	}
	return 0;
}