zadania b00,b01
This commit is contained in:
parent
cb669e1c86
commit
3b17708166
26
TaskB00/run.py
Normal file
26
TaskB00/run.py
Normal 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.
12
TaskB01/fsa_description.arg
Normal file
12
TaskB01/fsa_description.arg
Normal 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
27
TaskB01/run.py
Normal 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")
|
BIN
TaskB01/test.exp
BIN
TaskB01/test.exp
Binary file not shown.
Loading…
Reference in New Issue
Block a user