Language: C++

#include<iostream>
#include<cfloat>
#include<cmath>
using namespace std;

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

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

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}#include<iostream>
#include<cfloat>
#include<cmath>
using namespace std;

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

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

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}


Compiler output:
a.cc:52:2: error: stray '#' in program
   52 | }#include<iostream>
      |  ^
a.cc: In function 'int main()':
a.cc:41:39: error: reference to 'data' is ambiguous
   41 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                       ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:41:66: error: reference to 'data' is ambiguous
   41 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                                                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:41:93: error: reference to 'data' is ambiguous
   41 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                                                                             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc: At global scope:
a.cc:52:3: error: 'include' does not name a type
   52 | }#include<iostream>
      |   ^~~~~~~
a.cc:57:5: error: redefinition of 'int hexToDec(char)'
   57 | int hexToDec(char x){
      |     ^~~~~~~~
a.cc:6:5: note: 'int hexToDec(char)' previously defined here
    6 | int hexToDec(char x){
      |     ^~~~~~~~
a.cc:65:5: error: redefinition of 'int data [8][3]'
   65 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:14:5: note: 'int data [8][3]' previously defined here
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:74:8: error: redefinition of 'std::string color [8]'
   74 | string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
      |        ^~~~~
a.cc:23:8: note: 'std::string color [8]' previously declared here
   23 | string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
      |        ^~~~~
a.cc:76:5: error: redefinition of 'int main()'
   76 | int main(){
      |     ^~~~
a.cc:25:5: note: 'int main()' previously defined here
   25 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:92:39: error: reference to 'data' is ambiguous
   92 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                       ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:92:66: error: reference to 'data' is ambiguous
   92 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                                                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~
a.cc:92:93: error: reference to 'data' is ambiguous
   92 |             double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
      |                                                                                             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:14:5: note:                 'int data [8][3]'
   14 | int data[8][3] = { {0, 0, 0}   ,
      |     ^~~~