import sys sys.setrecursionlimit(1000000) sys.stdout.reconfigure(encoding="utf-8", newline="\n") print("Expert zo zoo to vie.") raw = sys.stdin.read() rows = raw.split("\n") if rows[-1] == "": rows.pop() rows = [r.rstrip("\r") for r in rows] pos = 0 question_count = 0 answer_count = 0 def bad_database(): print("Chybna databaza") exit() def load(): global pos, question_count, answer_count if pos >= len(rows): bad_database() text = rows[pos] pos += 1 if text == "": bad_database() if "?" == text[-1]: question_count = question_count + 1 left = load() right = load() return (text, left, right) else: answer_count += 1 return (text,) tree = load() if pos < len(rows): if rows[pos] != "": bad_database() answers = rows[pos + 1:] print("Pocet otazok:", question_count) print("Pocet odpovedi:", answer_count) print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.") current = tree print(current[0]) step = 0 while len(current) > 1: if step == len(answers): print("Koniec vstupu") exit() choice = answers[step] step += 1 if choice == "a": current = current[1] elif choice == "n": current = current[2] else: print("Nerozumiem") exit() print(current[0]) print("Koniec")