38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import sys
|
|
|
|
fsa_description = sys.argv[1]
|
|
inputWords = sys.argv[2]
|
|
outputResult = sys.argv[3]
|
|
|
|
def readDescription(currentPos, charInput):
|
|
with open(fsa_description, 'r', encoding="utf-8") as descript:
|
|
for line in descript:
|
|
if len(line.strip().split(' ')) == 1:
|
|
return line[0], 0
|
|
transition = line.strip().split(' ')
|
|
if len(transition) == 3 and currentPos == transition[0] and charInput == transition[2]:
|
|
return transition[1], 1
|
|
return None, None
|
|
|
|
answersYN = ''
|
|
with open(inputWords, 'r', encoding="utf-8") as inputString:
|
|
for line in inputString:
|
|
pos = '0'
|
|
for char in line:
|
|
if char == '\n':
|
|
answersYN += ('1' if pos == '3' or pos == '0' else '0')
|
|
break
|
|
newPos, flag = readDescription(pos, char)
|
|
if flag == 1:
|
|
pos = newPos
|
|
|
|
with open(outputResult, 'w', encoding="utf-8") as output:
|
|
for i in range(0, len(answersYN)):
|
|
if answersYN[i] == '1':
|
|
# print("YES")
|
|
output.write("YES\n")
|
|
elif answersYN[i] == '0':
|
|
# print("NO")
|
|
output.write("NO\n")
|
|
|
|
print(answersYN) |