'hm'
This commit is contained in:
parent
7b8eaaa567
commit
7c5f6bb09a
46
TaskB01/run
Normal file
46
TaskB01/run
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python3
|
||||
import sys
|
||||
import re
|
||||
|
||||
|
||||
class automate:
|
||||
self.storage = []
|
||||
self.accepting_states = []
|
||||
self.state = '0'
|
||||
|
||||
def add_node(self, line):
|
||||
node = line.split(' ')
|
||||
if len(node) == 3:
|
||||
self.storage.append([[node[0], node[2]], node[1]])
|
||||
elif len(node) == 1:
|
||||
self.accepting_states.append()
|
||||
|
||||
def test_string(self, text):
|
||||
|
||||
for i in text:
|
||||
self.state = self.get_node_transition([self.state, i])
|
||||
if self.state == None:
|
||||
return 'FALSE'
|
||||
|
||||
if self.state in self.accepting_states:
|
||||
return 'TRUE'
|
||||
else:
|
||||
return 'FALSE'
|
||||
|
||||
|
||||
def get_node_transition(self, query):
|
||||
for i in self.storage:
|
||||
if i[0] == query:
|
||||
return i[1]
|
||||
return None
|
||||
|
||||
|
||||
auto = automate()
|
||||
|
||||
for line in sys.stdin:
|
||||
auto.add_node(line)
|
||||
|
||||
f = open(sys.argv[1], 'r')
|
||||
|
||||
for line in f:
|
||||
print(auto.test_string(line))
|
Loading…
Reference in New Issue
Block a user