# DFA

Viết chương trình mô phỏng hoạt động của 1 DFA với một chuỗi nhập đầu vào.
user_5119020710
python
a year ago
2.2 kB
5
Indexable
Never
```class DFA:
def __init__(self):
self.QArr = {}
self.AlphabetArr = {}
self.AcceptArr = {}
self.stateDest = {}
self.s = ''
def __init__(self,QArr,AlphabetArr,AcceptArr,stateDest,s):
self.QArr = QArr
self.AlphabetArr = AlphabetArr
self.AcceptArr = AcceptArr
self.stateDest = stateDest
self.s = s
def setQArr(self,QArr):
self.QArr = QArr

def setAlphabetArr(self,AlphabetArr):
self.AlphabetArr = AlphabetArr

def setAcceptArr(self,AcceptArr):
self.AcceptArr = AcceptArr

def setStateDest(self,stateDest):
self.stateDest = stateDest

def setS(self,s):
self.s = s

def input(self):
self.n, self.m = input().split()
self.QArr = list(map(int, input().split()))
self.AlphabetArr = input().split()
self.AcceptArr = list(map(int, input().split()))
self.stateDest = {}
for i in range(1, int(self.m)*int(self.n)+1):
InputArr=input().split()
state={}
state[InputArr[0]+' '+InputArr[1]] = int(InputArr[2])
self.stateDest.update(state)

def inputS(self):
self.s =  input()

def checkSyntax(self,s):
for c in s:
if (c not in self.AlphabetArr):
return False
return True

def check(self):
current = 0
if (not self.checkSyntax(s)):
print("NO")
return

for c in self.s:
current = self.stateDest[str(current)+' '+c]

if int(current) in self.AcceptArr:
print("YES")
else:
print("NO")

n, m = input().split()
QArr = list(map(int, input().split()))
AlphabetArr = input().split()
AcceptArr = list(map(int, input().split()))
stateDest = {}
for i in range(1, int(m)*int(n)+1):
InputArr=input().split()
state={}
state[InputArr[0]+' '+InputArr[1]] = int(InputArr[2])
stateDest.update(state)
s = input()

test = DFA(QArr,AlphabetArr,AcceptArr,stateDest,s)
test.check()
```