Taro shows a magic trick to Hanako.
Taro: Hello Hanako. I’ll show you a magic trick. Please imagine a positive integer less than or equal to 16.
Hanako: OK. I imagined it.
Taro: (Taro shows card 1 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 2 to Hanako.) Does this card contain your number?
Hanako: No.
Taro: (Taro shows card 3 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 4 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: Your number is 5!
#include <string>
using namespace std;
class NumberMagicEasy {
char Check(int x[], int number){
for (int x=0; x<8; x++){
if(X[x] == number) return 'Y';
}
return 'N';
}
public:
int theNumber(string answer) {
int A[] = {1, 2, 3, 4, 5, 6, 7, 8};
int B[] = {1, 2, 3, 4, 9, 10, 11, 12};
int C[] = {1, 2, 5, 6, 9, 10, 13, 14};
int A[] = {1, 3, 5, 7, 9, 11, 13, 15};
for (int i = 1; i <= 16; i++){
if(Check(A, i) != answer[0]) continue;
if(Check(B, i) != answer[0]) continue;
if(Check(C, i) != answer[0]) continue;
if(Check(D, i) != answer[0]) continue;
return i;
}
return 0;
}
}
class NumberMagicEasy {
public:
int theNumber(string answer){
string c[] = {
"YYYYYYYYNNNNNNNN",
"YYYYNNNNYYYYNNNN",
"YYNNYYNNYYNNYYNN",
"YNYNYNYNYNYNYNYN",
};
for(int i=0; i<=15; i++){
string temp="";
for(int j=0; j<4; j++) temp += c[j][i];
if(answer == temp) return i+1;
}
}
}



