From 3e42bde5096a251bdff4c675c8c975ae282aa927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zofia=20B=C4=85czyk?= Date: Sun, 3 Jan 2021 16:43:31 +0100 Subject: [PATCH] attempt 1 --- TaskF03/Makefile | 0 TaskF03/run | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 TaskF03/Makefile create mode 100644 TaskF03/run diff --git a/TaskF03/Makefile b/TaskF03/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/TaskF03/run b/TaskF03/run new file mode 100644 index 0000000..22c5937 --- /dev/null +++ b/TaskF03/run @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +import sys +import re + +paths = {} +accpaths = [] +argfile = "0 1 a\n0 0 b\n0 0 c\n1 2 b\n1 1 a\n1 1 c\n2 3 c\n2 2 b\n2 2 a\n3 3 a\n3 3 b\n3 3 c\n3\n" +lines = argfile.splitlines(); +for line in lines: + answer = re.match('^([0-9]+) ([0-9]+) ([a-z]*)$', line); + if answer: + try: + try: + paths[answer.group(1)][answer.group(3)].add(answer.group(2)) + except KeyError: + paths[answer.group(1)][answer.group(3)] = {answer.group(2)} + except KeyError: + paths.update({answer.group(1):{}}) + paths[answer.group(1)][answer.group(3)] = {answer.group(2)} + else: + accpaths.append(line) +for input in sys.stdin.readlines(): + y = {str(0)} + for char in input[:-1]: + x = set() + for i in y: + try: + x.update(paths[i][char]) + except KeyError: + pass + y = x + if len(y.intersection(accpaths))>0: + print("YES") + else: + print("NO")