about summary refs log tree commit diff
path: root/usth/MATH2.3/5/automata.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/MATH2.3/5/automata.c')
-rw-r--r--usth/MATH2.3/5/automata.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/usth/MATH2.3/5/automata.c b/usth/MATH2.3/5/automata.c
new file mode 100644
index 0000000..d18ca1e
--- /dev/null
+++ b/usth/MATH2.3/5/automata.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main() {
+	int n;
+	scanf("%d", &n);
+
+	int F[n], f[n][2];
+	for (int i = 0; i < n; ++i)
+		scanf("%d %d %d", F + i, f[i], f[i] + 1);
+
+	int m;
+	scanf("%d ", &m);
+
+	char c[m + 1];
+	scanf("%s", c);
+
+	int state = 0;
+	for (int i = 0; i < m; ++i)
+		state = f[state][c[i] - 48];
+
+	puts(F[state] ? "yes" : "no");
+
+	return 0;
+}