Advertisement
Anon2005

Interactive

Nov 6th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include "header.h"
  3. using namespace std;
  4. int VAL_CAUTATA;
  5. char intreaba(int val)
  6. {
  7.     if(val<VAL_CAUTATA)
  8.         return '<';
  9.     else if(val==VAL_CAUTATA)
  10.         return '=';
  11.     else
  12.         return '>';
  13. }
  14. void raspunde(int val)
  15. {
  16.     if(val==VAL_CAUTATA)
  17.         cout<<"BRAVO! Ai gasit numarul ascuns";
  18.     else
  19.         cout<<"N-ai orizont";
  20. }
  21. int main()
  22. {
  23.     cin>>VAL_CAUTATA;
  24.     gaseste();
  25.     return 0;
  26. }
  27.  
  28.  
  29. void gaseste();
  30. void raspunde(int);
  31. char intreaba(int);
  32.  
  33.  
  34. #include <bits/stdc++.h>
  35. #include "header.h"
  36. using namespace std;
  37. void gaseste()
  38. {
  39.     int r=0,pas=1<<30;
  40.     char c;
  41.     while(pas)
  42.     {
  43.         c=intreaba(r+pas);
  44.         if(c=='<')
  45.             r+=pas;
  46.         else if(c=='=')
  47.         {
  48.             raspunde(r+pas);
  49.             exit(0);
  50.         }
  51.         pas/=2;
  52.     }
  53.     raspunde(r);
  54.     return;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement