Compare commits

..

2 Commits

Author SHA1 Message Date
IgnBys
26b4b6552e Merge branch 'master' of https://git.wmi.amu.edu.pl/s473579/jfz-2023-s473579 2023-11-01 22:39:38 +01:00
IgnBys
e87d5b53bd TaskB00 2023-11-01 22:36:00 +01:00
6 changed files with 79 additions and 0 deletions

8
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
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

29
run.py Normal file
View File

@ -0,0 +1,29 @@
import sys
def write_answer(answer):
with open('test1.out', 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open('fsa_description.arg', 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split('\t')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = sys.argv[1]
# input_file = sys.argv[2]
with open('test1.out', 'w') as readed_output_file:
with open('test1.in', 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='3':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

9
test1.exp Normal file
View File

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

9
test1.in Normal file
View File

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

8
test1.out Normal file
View File

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