daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <locale.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. unsigned short limit = 0;
  8.  
  9. void otgadayka(int a, int b)
  10. {
  11.     if (!limit)
  12.     {
  13.         cout << "Не ври, я давно уже отгдал!\n ";
  14.         return;
  15.     }
  16.     char input;
  17.     cout << "Я думаю, что это число: " << a + (b-a)/2 << endl;
  18.     --limit;
  19.     cin >> input;
  20.     if (input == '=')
  21.     {
  22.         cout << "Я отгадал!" << endl;
  23.         return;
  24.     }
  25.     if (input == '>')
  26.         otgadayka(a + (b - a) / 2 + 1, b);
  27.     else if (input == '<')
  28.         otgadayka(a, a + (b - a) / 2 - 1);
  29. }
  30.  
  31. int main()
  32. {
  33.     setlocale(LC_ALL, "ukr");
  34.     int a = 1,
  35.         b = 100;
  36.  
  37.     limit = ceil(log2(b - a));
  38.     cout << "Я отгадаю за " << limit << " попыток." << endl;
  39.     otgadayka(a, b);
  40.     return 0;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top