From 386edf797cf57edbc6cb3773bb7eb581cee834d5 Mon Sep 17 00:00:00 2001 From: doasdsk Date: Fri, 10 Nov 2023 21:25:32 +0100 Subject: [PATCH] B04 --- TaskB04/fsa_description.arg | 10 +++++++++ TaskB04/run.py | 43 +++++++++++++++++++++++++++++++++++++ TaskB04/test.out | 14 ++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 TaskB04/fsa_description.arg create mode 100644 TaskB04/run.py create mode 100644 TaskB04/test.out diff --git a/TaskB04/fsa_description.arg b/TaskB04/fsa_description.arg new file mode 100644 index 0000000..8b88898 --- /dev/null +++ b/TaskB04/fsa_description.arg @@ -0,0 +1,10 @@ +0 1 0 +0 3 1 +1 0 0 +1 2 1 +2 3 0 +2 1 1 +3 2 0 +3 0 1 +1 +2 \ No newline at end of file diff --git a/TaskB04/run.py b/TaskB04/run.py new file mode 100644 index 0000000..94cdf68 --- /dev/null +++ b/TaskB04/run.py @@ -0,0 +1,43 @@ +import sys + +# fsa_description = sys.argv[1] +# inputWords = sys.argv[2] +# outputResult = sys.argv[3] + +fsa_description = "fsa_description.arg" +inputWords = "test.in" +outputResult = "test.out" + + +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 == '1' or 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") + output.write("YES\n") + elif answersYN[i] == '0': + # print("NO") + output.write("NO\n") + +print(answersYN) \ No newline at end of file diff --git a/TaskB04/test.out b/TaskB04/test.out new file mode 100644 index 0000000..d40ad22 --- /dev/null +++ b/TaskB04/test.out @@ -0,0 +1,14 @@ +YES +YES +NO +NO +NO +YES +NO +YES +NO +YES +NO +NO +YES +NO