new
This commit is contained in:
parent
50c17e59ef
commit
537aea64a0
48
u8/program.py
Normal file
48
u8/program.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
def __init__(self, text, left = None, right = None):
|
||||||
|
self.text = text
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Expert zo zoo to vie.")
|
||||||
|
input_data = sys.stdin.read()
|
||||||
|
lines = input_data.splitlines()
|
||||||
|
if not lines:
|
||||||
|
print("Chybna databaza")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
q_counter = 0
|
||||||
|
a_counter = 0
|
||||||
|
idx = 0
|
||||||
|
|
||||||
|
def parse_tree():
|
||||||
|
nonlocal idx, q_counter, a_counter
|
||||||
|
if idx >= len(lines):
|
||||||
|
return None
|
||||||
|
line = lines[idx]
|
||||||
|
idx = idx + 1
|
||||||
|
|
||||||
|
|
||||||
|
if line == "":
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
if line.endswith('?'):
|
||||||
|
q_counter = q_counter + 1
|
||||||
|
left = parse_tree()
|
||||||
|
if left is None:
|
||||||
|
return None
|
||||||
|
right = parse_tree()
|
||||||
|
if right is None:
|
||||||
|
return None
|
||||||
|
return Node(line, left, right)
|
||||||
|
else:
|
||||||
|
a_counter = a_counter + 1
|
||||||
|
return Node(line)
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user