#include #include #include using namespace std; class NumberMagicEasy { public: int theNumber(string answer); }; int NumberMagicEasy::theNumber(string answer) { int i; int res; vector c; c.push_back((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8)); c.push_back((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)); c.push_back((1 << 1) | (1 << 2) | (1 << 5) | (1 << 6) | (1 << 9) | (1 << 10) | (1 << 13) | (1 << 14)); c.push_back((1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 11) | (1 << 13) | (1 << 15)); for (i = 0; i < 4; i++) if (answer[i] == 'N') c[i] = ~c[i]; res = c[0] & c[1] & c[2] & c[3]; for (i = 1; i <= 16; i++) if (res & (1 << i)) return i; return -1; // This won't happen, but it shuts the compiler up and helps find bugs. }