#include <iostream>
int main()
{
int L = 0;
int R = 101;
char spell = true;
std::cout << "Is the number you thought of larger than (please, input 'y', 'n' or '=') " << 50 << "? ";
while (std::cin >> spell)
{
if (spell != 'y' && spell != 'n' && spell != '=')
{
std::cout << "Please, input 'y', 'n' or '=': " << std::endl;
continue;
}
int M = (L + R) / 2;
if (spell == '=')
{
std::cout << "The number you thought of is " << M << "!" << std::endl;
break;
}
switch (spell)
{
case 'y':
{
L = M;
break;
}
case 'n':
{
R = M;
break;
}
}
M = (L + R) / 2;
std::cout << "Is the number you thought of larger than " << M << "? ";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKaW50IG1haW4oKQp7CglpbnQgTCA9IDA7CglpbnQgUiA9IDEwMTsKCWNoYXIgc3BlbGwgPSB0cnVlOwoJc3RkOjpjb3V0IDw8ICJJcyB0aGUgbnVtYmVyIHlvdSB0aG91Z2h0IG9mIGxhcmdlciB0aGFuIChwbGVhc2UsIGlucHV0ICd5JywgJ24nIG9yICc9JykgIiA8PCA1MCA8PCAiPyAiOwoJd2hpbGUgKHN0ZDo6Y2luID4+IHNwZWxsKQoJewoJCWlmIChzcGVsbCAhPSAneScgJiYgc3BlbGwgIT0gJ24nICYmIHNwZWxsICE9ICc9JykKCQl7CgkJCXN0ZDo6Y291dCA8PCAiUGxlYXNlLCBpbnB1dCAneScsICduJyBvciAnPSc6ICIgPDwgc3RkOjplbmRsOwoJCQljb250aW51ZTsKCQl9CgoJCWludCBNID0gKEwgKyBSKSAvIDI7CgoJCWlmIChzcGVsbCA9PSAnPScpCgkJewoJCQlzdGQ6OmNvdXQgPDwgIlRoZSBudW1iZXIgeW91IHRob3VnaHQgb2YgaXMgIiA8PCBNIDw8ICIhIiA8PCBzdGQ6OmVuZGw7CgkJCWJyZWFrOwoJCX0KCgkJc3dpdGNoIChzcGVsbCkKCQl7CgkJCWNhc2UgJ3knOgoJCQl7CgkJCQlMID0gTTsKCQkJCWJyZWFrOwoJCQl9CgkJCWNhc2UgJ24nOgoJCQl7CgkJCQlSID0gTTsKCQkJCWJyZWFrOwoJCQl9CgkJfQoKCQlNID0gKEwgKyBSKSAvIDI7CgoJCXN0ZDo6Y291dCA8PCAiSXMgdGhlIG51bWJlciB5b3UgdGhvdWdodCBvZiBsYXJnZXIgdGhhbiAiIDw8IE0gPDwgIj8gIjsKCX0KfQ==