From bcc38555ea8da30afd8d0e8314e2ef8d02004a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 14 Dec 2021 21:44:53 +0100 Subject: ne glej vsebine tega commita prosim --- inf/liga/1.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 inf/liga/1.c (limited to 'inf/liga/1.c') diff --git a/inf/liga/1.c b/inf/liga/1.c new file mode 100644 index 0000000..955cd89 --- /dev/null +++ b/inf/liga/1.c @@ -0,0 +1,49 @@ +#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; +} -- cgit v1.2.3