Le dimanche 1 avril 2018 10:10:46 UTC+2, Xiongqi ZHANG a écrit :
> Would you share your python solution? Maybe we can take a look.

Here mine, .. keep having "Runtime Error"

import sys


def guess_nb(a, b):
    if a > b:
        buff = a
        a = b
        b = buff
    guessnb = int((b - a) / 2) + a
    return int(guessnb)


print("Starting\n", flush=True,file=sys.stderr)
T = int(sys.stdin.readline())
while T > 0:

    line = sys.stdin.readline()
    A, B = line.rsplit()
    A = int(A)
    B = int(B)
    N = int(sys.stdin.readline())
    while N:
        print(f"A={A} B={B} N={N}", flush=True, file=sys.stderr)
        nb = guess_nb(A, B)
        print(nb, flush=True)
        print(nb, flush=True, file=sys.stderr)
        rep = sys.stdin.readline().rstrip()
        print("["+rep+"]", flush=True, file=sys.stderr)
        if rep == "TOO_SMALL":
            A = nb
            N -= 1
        elif rep == "TOO_BIG":
            B = nb
            N -= 1
        elif rep == "CORRECT":
            N=0
        elif rep == "WRONG_ANSWER":
            N = 0
        else:
            exit(2)
            print("Error rep not found", flush=True, file=sys.stderr)
    T -= 1






-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/cc283c0a-cb40-4bcc-95f7-8446e0a930de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to