update
This commit is contained in:
parent
3a02c4d687
commit
4b285f9bd8
@ -22,7 +22,7 @@ class FSA():
|
||||
{'in': '4', 'letter': 'e', 'out': '5'},
|
||||
{'in': '5', 'letter': 't', 'out': '6'},
|
||||
{'in': '6', 'letter': 'h', 'out': '7'},
|
||||
{'in': ['1', '2', '3', '4', '5', '6'], 'letter': 'x', 'out': '8'}]
|
||||
{'in': ['0', '1', '2', '3', '4', '5', '6'], 'letter': 'x', 'out': '0'}]
|
||||
|
||||
def add_letter_to_alphabet(self, letter):
|
||||
self.alphabet.add(letter)
|
||||
@ -36,8 +36,6 @@ class FSA():
|
||||
self.end_state = end_state
|
||||
|
||||
def check_text(self, text):
|
||||
output_text = ""
|
||||
|
||||
for letter in text:
|
||||
found_function = None
|
||||
|
||||
@ -47,27 +45,16 @@ class FSA():
|
||||
|
||||
if not found_function:
|
||||
self.current_state = '0'
|
||||
output_text = ""
|
||||
else:
|
||||
self.current_state = found_function['out']
|
||||
output_text += found_function['letter']
|
||||
|
||||
# print('Input text:{} output text:{} current state:{}'.format(text, output_text, self.current_state))
|
||||
if output_text == 'Macbeth' and self.current_state == self.acceptance_state:
|
||||
if self.current_state == self.acceptance_state:
|
||||
return 'YES'
|
||||
|
||||
return 'NO'
|
||||
|
||||
FSA = FSA()
|
||||
|
||||
# for line in file:
|
||||
# line = line.rstrip('\n').split(' ')
|
||||
# if len(line) > 1:
|
||||
# FSA.add_transition_to_transition_function(line[0], line[1], line[2])
|
||||
# FSA.add_letter_to_alphabet(line[2])
|
||||
# else:
|
||||
# FSA.specify_end_state(line[0])
|
||||
|
||||
lines = ['My name’s Macbeth.']
|
||||
|
||||
for line in sys.stdin:
|
||||
|
@ -35,8 +35,6 @@ class FSA():
|
||||
if text == '':
|
||||
return 'YES'
|
||||
|
||||
output_text = ""
|
||||
|
||||
for letter in text:
|
||||
if letter not in self.alphabet:
|
||||
return 'NO'
|
||||
@ -51,11 +49,10 @@ class FSA():
|
||||
self.current_state = '0'
|
||||
else:
|
||||
self.current_state = found_function['out']
|
||||
output_text += found_function['letter']
|
||||
|
||||
# print('Input text:{} output text:{} current state:{}'.format(text, output_text, self.current_state))
|
||||
if output_text == text and self.current_state == self.acceptance_state:
|
||||
return 'YES'
|
||||
if self.current_state == self.acceptance_state:
|
||||
return 'YES'
|
||||
|
||||
return 'NO'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user