Problem p00176 (C++) — buggy submission, verdict: Runtime Error

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

class Col {
public:
  int R, G, B;
  Col() : R(0), G(0), B(0) {}
  Col(int R, int G, int B) : R(R), G(G), B(B) {}
};

int _16to10(string s) {
  int a[2];
  for (int i = 0; i < 2; i++) {
    if (s[i] == 'a')
      a[i] = 10;
    else if (s[i] == 'b')
      a[i] = 11;
    else if (s[i] == 'c')
      a[i] = 12;
    else if (s[i] == 'd')
      a[i] = 13;
    else if (s[i] == 'e')
      a[i] = 14;
    else if (s[i] == 'f')
      a[i] = 15;
    else
      a[i] = s[i] - '0';
  }
  return a[1] + a[0] * 16;
}

int main() {
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8), name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0, 0, 0);
  vec[1] = Col(0, 0, ff);
  vec[2] = Col(0, ff, 0);
  vec[3] = Col(0, ff, ff);
  vec[4] = Col(ff, 0, 0);
  vec[5] = Col(ff, 0, ff);
  vec[6] = Col(ff, ff, 0);
  vec[7] = Col(ff, ff, ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while (true) {
    cin >> s;
    if (s == "0")
      break;
    int R, G, B;
    R = _16to10(s.substr(1, 2));
    G = _16to10(s.substr(3, 2));
    B = _16to10(s.substr(5, 2));

    double men = (1 << 28), pos = -1;
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(R - vec[i].R, 2) + pow(B - vec[i].B, 2) +
                      pow(G - vec[i].G, 2));
      if (men > d) {
        men = d;
        pos = i;
      }
    }
    cout << name[pos] << endl;
  }
  return 0;
}

Error: 0
#ffe085
#787878
#decade
#ff55ff
0


Fixed submission:

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

class Col {
public:
  int R, G, B;
  Col() : R(0), G(0), B(0) {}
  Col(int R, int G, int B) : R(R), G(G), B(B) {}
};

int _16to10(string s) {
  int a[2];
  for (int i = 0; i < 2; i++) {
    if (s[i] == 'a')
      a[i] = 10;
    else if (s[i] == 'b')
      a[i] = 11;
    else if (s[i] == 'c')
      a[i] = 12;
    else if (s[i] == 'd')
      a[i] = 13;
    else if (s[i] == 'e')
      a[i] = 14;
    else if (s[i] == 'f')
      a[i] = 15;
    else
      a[i] = s[i] - '0';
  }
  return a[1] + a[0] * 16;
}

int main() {
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8), name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0, 0, 0);
  vec[1] = Col(0, 0, ff);
  vec[2] = Col(0, ff, 0);
  vec[3] = Col(0, ff, ff);
  vec[4] = Col(ff, 0, 0);
  vec[5] = Col(ff, 0, ff);
  vec[6] = Col(ff, ff, 0);
  vec[7] = Col(ff, ff, ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while (true) {
    cin >> s;
    cerr << s << endl;
    if (s == "0")
      break;
    int R, G, B;
    R = _16to10(s.substr(1, 2));
    G = _16to10(s.substr(3, 2));
    B = _16to10(s.substr(5, 2));

    int men = (1 << 28), pos = -1;
    for (int i = 0; i < 8; i++) {
      int d = sqrt(pow(R - vec[i].R, 2) + pow(B - vec[i].B, 2) +
                   pow(G - vec[i].G, 2));
      if (men > d) {
        men = d;
        pos = i;
      }
    }
    cout << name[pos] << endl;
  }
  return 0;
}