Prześlij pliki do 'B00'

This commit is contained in:
Yevheniia Kryzhanovska 2023-11-10 12:13:13 +01:00
parent 5c79097202
commit f92640b359
5 changed files with 125 additions and 0 deletions

8
B00/description.txt Normal file
View File

@ -0,0 +1,8 @@
Read a description of a deterministic finite-state automaton in the AT&T format
(without weights) from the file in the first argument.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.
The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out

16
B00/fsa_description.arg Normal file
View File

@ -0,0 +1,16 @@
0 1 x
1 2 y
2 3 z
0 4 y
0 4 z
1 4 x
1 4 z
2 4 x
2 4 y
3 4 x
3 4 y
3 4 z
4 4 x
4 4 y
4 4 z
3

2
B00/read.txt Normal file
View File

@ -0,0 +1,2 @@
windows
py .\run.py .\fsa_description.arg .\test1.in .\test1.out

90
B00/run.py Normal file
View File

@ -0,0 +1,90 @@
import sys
# global fsa_description
# global inputWords
# global outputResult
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('\t')) == 1:
return line[0], 0
transition = line.strip().split('\t')
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' else '0')
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':
output.write("YES\n")
elif answersYN[i] == '0':
output.write("NO\n")
print(answersYN)
#
# import sys
#
# acceptingPos = None
# def readDescription(currentPos, charInput):
# with open("fsa_description.arg", 'r', encoding="utf-8") as descript:
# # global acceptingPos
#
# for line in descript:
# if line.strip().split('\t')==1:
# # acceptingPos = line[0]
# return line[0], 0
# transition = line.strip().split('\t')
#
# if currentPos == transition[0] and charInput == transition[2]:
# return transition[1],1
# return None, None
#
# # startPos, endPos, char =
# # if currentPos==startPos and charInput==char:
# # currentPos = endPos
# # return currentPos, 1
#
# # return None, None
#
#
#
# answersYN=''
# with open("test1.in", 'r', encoding="utf-8") as inputString:
# currentPos=None
# for line in inputString:
# pos = '0'
# for char in line:
#
# if char == '\n':
# if pos == '3' :
# answersYN +='1'
#
# else:
# answersYN +='0'
# newPos, flag = readDescription(pos, char)
# if flag==1:
# pos = newPos
#
#
# print(answersYN)
#

9
B00/test1.exp Normal file
View File

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