From 1148f1d95199cdda1df58d0dc7ad38dafa91e723 Mon Sep 17 00:00:00 2001 From: doasdsk Date: Fri, 10 Nov 2023 20:59:38 +0100 Subject: [PATCH] B02 --- TaskB02/fsa_description.arg | 13 +++++++++++++ TaskB02/run.py | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 TaskB02/fsa_description.arg create mode 100644 TaskB02/run.py diff --git a/TaskB02/fsa_description.arg b/TaskB02/fsa_description.arg new file mode 100644 index 0000000..9c18648 --- /dev/null +++ b/TaskB02/fsa_description.arg @@ -0,0 +1,13 @@ +0 3 0 +0 1 1 +1 2 0 +1 3 1 +2 4 0 +2 5 1 +3 3 0 +3 3 1 +4 4 0 +4 5 1 +5 2 0 +5 5 1 +2 diff --git a/TaskB02/run.py b/TaskB02/run.py new file mode 100644 index 0000000..4e8be21 --- /dev/null +++ b/TaskB02/run.py @@ -0,0 +1,39 @@ +import sys + +fsa_description = sys.argv[1] +inputWords = sys.argv[2] +outputResult = sys.argv[3] + + +def readDescription(currentPos, charInput): + with open(fsa_description, 'r', encoding="utf-8") as descript: + for line in descript: + if len(line.strip().split(' ')) == 1: + return line[0], 0 + transition = line.strip().split(' ') + if len(transition) == 3 and currentPos == transition[0] and charInput == transition[2]: + return transition[1], 1 + return None, None + +answersYN = '' +with open(inputWords, 'r', encoding="utf-8") as inputString: + for line in inputString: + pos = '0' + for char in line: + if char == '\n': + answersYN += ('1' if pos == '2' else '0') + break + newPos, flag = readDescription(pos, char) + if flag == 1: + pos = newPos + +with open(outputResult, 'w', encoding="utf-8") as output: + for i in range(0, len(answersYN)): + if answersYN[i] == '1': + # print("YES\n") + output.write("YES\n") + elif answersYN[i] == '0': + # print("NO\n") + output.write("NO\n") + +print(answersYN) \ No newline at end of file