This commit is contained in:
deadsmond 2019-11-24 21:27:57 +01:00
parent 9f526498a9
commit 98787b1efb

View File

@ -3,10 +3,11 @@ import sys
import re import re
class automate: class automata:
self.storage = [] def __init__(self):
self.accepting_states = [] self.storage = []
self.state = '0' self.accepting_states = []
self.state = '0'
def add_node(self, line): def add_node(self, line):
node = line.split(' ') node = line.split(' ')
@ -16,17 +17,16 @@ class automate:
self.accepting_states.append() self.accepting_states.append()
def test_string(self, text): def test_string(self, text):
for i in text: for i in text:
self.state = self.get_node_transition([self.state, i]) self.state = self.get_node_transition([self.state, i])
if self.state == None: if self.state == None:
return 'FALSE' return 'FALSE'
if self.state in self.accepting_states: if self.state in self.accepting_states:
return 'TRUE' return 'TRUE'
else: else:
return 'FALSE' return 'FALSE'
def get_node_transition(self, query): def get_node_transition(self, query):
for i in self.storage: for i in self.storage:
@ -35,7 +35,7 @@ class automate:
return None return None
auto = automate() auto = automata()
for line in sys.stdin: for line in sys.stdin:
auto.add_node(line) auto.add_node(line)