This commit is contained in:
wojtekgoralewski 2023-11-11 20:54:01 +01:00
parent a6ab6337cd
commit 3fc990152e
5 changed files with 110 additions and 10 deletions

View File

@ -6,7 +6,7 @@ def read_aut(fsa_path):
accepting_states = set() accepting_states = set()
for line in file: for line in file:
parts = line.strip().split() parts = line.strip().split()
print(parts) #print(parts)
if len(parts) == 1: if len(parts) == 1:
accepting_states.add(int(parts[0])) accepting_states.add(int(parts[0]))
#print(accepting_states) #print(accepting_states)
@ -15,7 +15,7 @@ def read_aut(fsa_path):
state_to = int(parts[1]) state_to = int(parts[1])
symbol = parts[2] symbol = parts[2]
transisions[(state_from, symbol)] = state_to transisions[(state_from, symbol)] = state_to
print(transisions) #print(transisions)
return transisions, accepting_states return transisions, accepting_states
#print(transisions) #print(transisions)
@ -24,6 +24,7 @@ def is_accepting(transitions, accepting_states, line):
for symbol in line.strip(): for symbol in line.strip():
if (current_state, symbol) in transitions: if (current_state, symbol) in transitions:
current_state = transitions[(current_state, symbol)] current_state = transitions[(current_state, symbol)]
#print(current_state)
else: else:
return "NO" return "NO"
if current_state in accepting_states: if current_state in accepting_states:

View File

@ -1,11 +1,3 @@
['0', '1', '1']
['0', '2', '0']
['1', '1', '1']
['1', '2', '0']
['2', '2', '1']
['2', '1', '0']
['2']
{(0, '1'): 1, (0, '0'): 2, (1, '1'): 1, (1, '0'): 2, (2, '1'): 2, (2, '0'): 1}
YES YES
YES YES
NO NO

View File

@ -0,0 +1,56 @@
0 1 1
0 0 0
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
0 0 x
1 0 0
1 1 1
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
1 2 9
1 0 x
2 0 x
2 3 0
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
2 3 7
2 3 8
2 3 9
3 0 x
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
4 4 0
4 4 1
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
4 4 x
4

45
TaskB05/run.py Normal file
View File

@ -0,0 +1,45 @@
import sys
def read_aut(fsa_path):
with open(fsa_path, "r", encoding="utf8") as file:
transisions = {}
accepting_states = set()
for line in file:
parts = line.strip().split()
#print(parts)
if len(parts) == 1:
accepting_states.add(int(parts[0]))
#print(accepting_states)
if len(parts) == 3:
state_from = int(parts[0])
state_to = int(parts[1])
symbol = parts[2]
transisions[(state_from, symbol)] = state_to
#print(transisions)
return transisions, accepting_states
#print(transisions)
def is_accepting(transitions, accepting_states, line):
current_state = 0 #zakładam, że zawsze stan początkowy to 0 dla uproszczenia
for symbol in line.strip():
if (current_state, symbol) in transitions:
current_state = transitions[(current_state, symbol)]
#print(current_state)
else:
return "NO"
if current_state in accepting_states:
return "YES"
else:
return "NO"
fsa_path = sys.argv[1]
transitions, accepting_states = read_aut(fsa_path)
for line in sys.stdin:
result = is_accepting(transitions, accepting_states, line)
#sys.stdout.write(result + '\n')
print(result)
#python run.py fsa_description.arg < test1.in > test1.out

6
TaskB05/test.out Normal file
View File

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