SuitNdtie

NumberGuessing

Apr 7th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6.     int T;
  7.     scanf("%d",&T);
  8.    
  9.     for(int t=1;t<=T;t++){
  10.         int a,b;
  11.         scanf("%d %d",&a,&b);
  12.         a++;
  13.         int n;
  14.         scanf("%d",&n);
  15.         int i = 0;
  16.         char str[20];
  17.         do{
  18.             int m = (a+b)/2;
  19.             printf("%d\n",m);
  20.             i++;
  21.             fflush(stdout);
  22.             scanf("%s",str);
  23.             if(!strcmp(str,"WRONG_ANSWER"))return -1;
  24.             if(!strcmp(str,"TOO_SMALL")){
  25.                 a = m + 1;
  26.             }
  27.             else if(!strcmp(str,"TOO_BIG")){
  28.                 b = m - 1;
  29.             }
  30.         }while(strcmp(str,"CORRECT") && i < n);
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment