Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale.h>
- #include <math.h>
- using namespace std;
- unsigned short limit = 0;
- void otgadayka(int a, int b)
- {
- if (!limit)
- {
- cout << "Не ври, я давно уже отгдал!\n ";
- return;
- }
- char input;
- cout << "Я думаю, что это число: " << a + (b-a)/2 << endl;
- --limit;
- cin >> input;
- if (input == '=')
- {
- cout << "Я отгадал!" << endl;
- return;
- }
- if (input == '>')
- otgadayka(a + (b - a) / 2 + 1, b);
- else if (input == '<')
- otgadayka(a, a + (b - a) / 2 - 1);
- }
- int main()
- {
- setlocale(LC_ALL, "ukr");
- int a = 1,
- b = 100;
- limit = ceil(log2(b - a));
- cout << "Я отгадаю за " << limit << " попыток." << endl;
- otgadayka(a, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement