This commit is contained in:
doasdsk 2023-11-10 20:40:04 +01:00
parent ab98ed1d4c
commit 346db007f5
5 changed files with 90 additions and 9 deletions

View File

@ -4,9 +4,14 @@ import sys
# global inputWords # global inputWords
# global outputResult # global outputResult
fsa_description = sys.argv[1]
inputWords = sys.argv[2] # fsa_description = sys.argv[1]
outputResult = sys.argv[3] # inputWords = sys.argv[2]
# outputResult = sys.argv[3]
fsa_description = "fsa_description.arg"
inputWords = "test1.in"
outputResult = "test1.out"
def readDescription(currentPos, charInput): def readDescription(currentPos, charInput):
with open(fsa_description, 'r', encoding="utf-8") as descript: with open(fsa_description, 'r', encoding="utf-8") as descript:
@ -29,11 +34,12 @@ with open(inputWords, 'r', encoding="utf-8") as inputString:
if flag == 1: if flag == 1:
pos = newPos pos = newPos
with open(outputResult, 'w', encoding="utf-8") as output: print(answersYN)
for i in range(0, len(answersYN)): # with open(outputResult, 'w', encoding="utf-8") as output:
if answersYN[i] == '1': # for i in range(0, len(answersYN)):
output.write("YES\n") # if answersYN[i] == '1':
elif answersYN[i] == '0': # output.write("YES\n")
output.write("NO\n") # elif answersYN[i] == '0':
# output.write("NO\n")

9
TaskB00/test1.in Normal file
View File

@ -0,0 +1,9 @@
xxyz
xyz
xy
zz
xxy
yzx
x
xyzz

View File

@ -0,0 +1,13 @@
0 1 0
0 3 1
1 2 1
1 3 0
2 4 1
2 5 0
3 3 0
3 3 1
4 4 1
4 5 0
5 5 0
5 2 1
2

39
TaskB01/run.py Normal file
View File

@ -0,0 +1,39 @@
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 == '2' 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\n")
output.write("YES\n")
elif answersYN[i] == '0':
# print("NO\n")
output.write("NO\n")
print(answersYN)

14
TaskB01/test.out Normal file
View File

@ -0,0 +1,14 @@
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO