Untested TaskB02

This commit is contained in:
Eryk Miszczuk 2019-12-02 21:39:01 +01:00
parent 2abcd00246
commit 216b5843f1
2 changed files with 47 additions and 0 deletions

2
TaskB02/run Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
python TaskB02/run.py "$@"

45
TaskB02/run.py Normal file
View File

@ -0,0 +1,45 @@
import re
import sys
atandt_desc_pattern = re.compile(r"^([0-9]+) ([0-9]+) (\S+)( [0-9]+\.[0-9]+)?$")
atandt_accepted_state_pattern = re.compile(r"^[0-9]+$")
current_state = 0
accept_states = []
state_move = {}
for line in sys.stdin:
line = line.replace('\n', '')
move = atandt_desc_pattern.match(line)
succes = atandt_accepted_state_pattern.match(line)
if move:
if move.group(4):
state_move[(int(move.group(1)), move.group(3))] = (int(move.group(2)), float(move.group(4)))
else:
state_move[(int(move.group(1)), move.group(3))] = (int(move.group(2)), 0)
if succes:
accept_states.append(int(line))
with open(sys.argv[1], 'r', encoding='utf-8') as f:
for word in f:
current_state = 0
word = word.replace('\n', '')
character_number = 0
while character_number < len(word):
if ((current_state, word[character_number]) in state_move):
current_state = state_move[(current_state, word[character_number])][1]
character_number += 1
elif (current_state, '<eps>') in state_move):
current_state = state_move[(current_state, '<eps>')][0]
else:
current_state = -1
character_number += 1
while ((current_state, '<eps>') in state_move):
current_state = state_move[(current_state, '<eps>')][0]
if (current_state in accept_states):
print("YES " + word)
else:
print("NO" + word)