Untested TaskB02
This commit is contained in:
parent
2abcd00246
commit
216b5843f1
2
TaskB02/run
Normal file
2
TaskB02/run
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
python TaskB02/run.py "$@"
|
45
TaskB02/run.py
Normal file
45
TaskB02/run.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user