zadania b00,b01

This commit is contained in:
Weranda 2023-10-30 15:09:25 +01:00
parent cb669e1c86
commit 3b17708166
5 changed files with 65 additions and 0 deletions

26
TaskB00/run.py Normal file
View File

@ -0,0 +1,26 @@
import sys
def is_accepted(fsa, input_string):
current_state = 0
for symbol in input_string:
if (current_state, symbol) in fsa:
current_state = fsa[(current_state, symbol)]
else:
return False
return current_state == 4
fsa_file = sys.argv[1]
fsa = {}
with open(fsa_file, 'r') as f:
for line in f:
parts = line.strip().split('\t')
if len(parts) == 3:
state, next_state, symbol = parts
fsa[(int(state), symbol)] = int(next_state)
for line in sys.stdin:
input_string = line.strip()
if is_accepted(fsa, input_string):
print("YES")
else:
print("NO")

Binary file not shown.

View File

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

27
TaskB01/run.py Normal file
View File

@ -0,0 +1,27 @@
import sys
def is_accepted(fsa, input_string):
current_state = 0
for symbol in input_string:
if (current_state, symbol) in fsa:
current_state = fsa[(current_state, symbol)]
else:
return False
return current_state == 2
fsa_file = sys.argv[1]
fsa = {}
with open(fsa_file, 'r') as f:
for line in f:
parts = line.strip().split(' ')
if len(parts) == 3:
state, next_state, symbol = parts
fsa[(int(state), symbol)] = int(next_state)
for line in sys.stdin:
input_string = line.strip()
if is_accepted(fsa, input_string):
print("YES")
else:
print("NO")

Binary file not shown.