#include #include #define M 512 #define pedantic_fgets(a, b, c) if (!fgets(a, b, c)) { fprintf(stderr, "napaka pri vnosu\n"); return 1; } int main (void) { char buf[M]; char * c; int a, b, s; pedantic_fgets(buf, M, stdin); a = strtol(buf, &c, 10); b = strtol(++c, NULL, 10); if (a > b) { s = a; /* swap */ a = b; b = s; } fprintf(stderr, "interval: %05d %05d\n", a, b); while (1) { int v, u; u = (a+b)/2; /* ugibamo to */ fprintf(stderr, "testiram %05d\n", u); pedantic_fgets(buf, M, stdin); if (!(v = strtol(buf, NULL, 10))) { if ((b-a) <= 1) goto ogabno; fprintf(stdout, "%d %d\n", a, b); return 0; /* da se CMS ne zmede */ } if ((b-a) <= 1) { /* našli smo število */ ogabno: if (v) fprintf(stdout, "PROTISLOVJE\n"); else fprintf(stdout, "%d\n", u); return 0; } if (v == -1) { b = u; b--; fprintf(stderr, "-1: število je manjše od %05d, interval %05d %05d\n", u, a, b); } if (v == 1) { a = u; a++; fprintf(stderr, " 1: število je večje od %05d, interval %05d %05d\n", u, a, b); } } return 0; }