32 lines
945 B
Python
32 lines
945 B
Python
|
import sys
|
||
|
|
||
|
def is_accepted(fsa, input_string):
|
||
|
current_state = 0
|
||
|
for symbol in input_string:
|
||
|
if symbol == ' ':
|
||
|
# If the current state is 6, stay in 6, otherwise transition to state 0
|
||
|
# PROGRAM NIE CHCE CZYTAĆ SPACJI JAKO ZNAK W PLIKU, ZAPISUJE JĄ JAKO PUSTY ZNAK
|
||
|
if current_state != 6:
|
||
|
current_state = 0
|
||
|
elif (current_state, symbol) in fsa:
|
||
|
current_state = fsa[(current_state, symbol)]
|
||
|
else:
|
||
|
return False
|
||
|
return current_state == 6
|
||
|
|
||
|
fsa_file = sys.argv[1]
|
||
|
fsa = {}
|
||
|
with open(fsa_file, 'r') as f:
|
||
|
for line in f:
|
||
|
parts = line.strip().split('-')
|
||
|
if len(parts) == 3:
|
||
|
state, next_state, symbol = parts
|
||
|
fsa[(int(state), symbol)] = int(next_state)
|
||
|
|
||
|
|
||
|
for line in sys.stdin:
|
||
|
input_string = line.strip()
|
||
|
if is_accepted(fsa, input_string):
|
||
|
print("YES")
|
||
|
else:
|
||
|
print("NO")
|