ndDA
This commit is contained in:
parent
6937996645
commit
5adaba293f
@ -2,74 +2,83 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, text, left = None, right = None):
|
def __init__(self, text, left=None, right=None):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.left = left
|
self.left = left
|
||||||
self.right = right
|
self.right = right
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Expert zo zoo to vie.")
|
print("Expert zo zoo to vie.")
|
||||||
|
|
||||||
input_data = sys.stdin.read()
|
input_data = sys.stdin.read()
|
||||||
|
if not input_data:
|
||||||
|
print("Chybna databaza")
|
||||||
|
return
|
||||||
|
|
||||||
lines = input_data.splitlines()
|
lines = input_data.splitlines()
|
||||||
if not lines:
|
if not lines:
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
q_counter = 0
|
q_counter = 0
|
||||||
a_counter = 0
|
a_counter = 0
|
||||||
idx = 0
|
idx = 0
|
||||||
|
|
||||||
def parse_tree():
|
def parse_tree():
|
||||||
nonlocal idx, q_counter, a_counter
|
nonlocal idx, q_counter, a_counter
|
||||||
if idx >= len(lines):
|
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
|
return None
|
||||||
right = parse_tree()
|
|
||||||
if right is None:
|
line = lines[idx]
|
||||||
|
idx += 1
|
||||||
|
|
||||||
|
if line == "":
|
||||||
return None
|
return None
|
||||||
return Node(line, left, right)
|
|
||||||
else:
|
if line.endswith('?'):
|
||||||
a_counter = a_counter + 1
|
q_counter += 1
|
||||||
return Node(line)
|
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 += 1
|
||||||
|
return Node(line)
|
||||||
|
|
||||||
root = parse_tree()
|
root = parse_tree()
|
||||||
|
|
||||||
|
|
||||||
if root is None or idx >= len(lines) or lines[idx] != "":
|
if root is None or idx >= len(lines) or lines[idx] != "":
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
print(f"Pocet otazok: {q_counter}")
|
print(f"Pocet otazok: {q_counter}")
|
||||||
print(f"Pocet odpovedi: {a_counter}")
|
print(f"Pocet odpovedi: {a_counter}")
|
||||||
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
||||||
|
|
||||||
idx += 1
|
|
||||||
|
|
||||||
|
idx += 1
|
||||||
|
|
||||||
current = root
|
current = root
|
||||||
while True:
|
while True:
|
||||||
print(current.text)
|
print(current.text)
|
||||||
|
|
||||||
|
|
||||||
if not current.text.endswith('?'):
|
if not current.text.endswith('?'):
|
||||||
print("Koniec")
|
print("Koniec")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
#koniec vstup
|
||||||
if idx >= len(lines):
|
if idx >= len(lines):
|
||||||
print("Koniec vstupu")
|
print("Koniec vstupu")
|
||||||
break
|
break
|
||||||
|
|
||||||
choice = lines[idx]
|
choice = lines[idx]
|
||||||
idx = idx + 1
|
idx += 1
|
||||||
|
|
||||||
if choice == 'a':
|
if choice == 'a':
|
||||||
current = current.left
|
current = current.left
|
||||||
@ -79,5 +88,6 @@ def main():
|
|||||||
print("Nerozumiem")
|
print("Nerozumiem")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user