-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDFA.cpp
More file actions
48 lines (47 loc) · 866 Bytes
/
DFA.cpp
File metadata and controls
48 lines (47 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
#pragma warning(disable: 4996)
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> term(n, 0);
vector<int> v0(30, -1);
vector<vector<int>> tab(n, v0);
for (int i = 0; i < n; i++) {
int s, t;
cin >> s >> t;
if (s) term[i]++;
int let, state;
for (int j = 0; j < t; j++) {
char c;
cin >> c >> state;
let = int(c) - 'a';
tab[i][let] = state;
}
}
int m;
cin >> m;
cout << int(term[0] != 0) << '\n';
for (int i = 0; i < m; i++) {
string word;
cin >> word;
int st = 0;
bool res = 1;
for (auto c : word) {
int x = int(c) - 'a';
if (tab[st][x] == -1) {
res = 0;
break;
}
st = tab[st][x];
}
if (!term[st]) res = 0;
cout << int(res) << '\n';
}
}