From f92640b359712a0c105f5f69f960a931dff08e22 Mon Sep 17 00:00:00 2001 From: Yevheniia Kryzhanovska Date: Fri, 10 Nov 2023 12:13:13 +0100 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20'B00'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- B00/description.txt | 8 ++++ B00/fsa_description.arg | 16 ++++++++ B00/read.txt | 2 + B00/run.py | 90 +++++++++++++++++++++++++++++++++++++++++ B00/test1.exp | 9 +++++ 5 files changed, 125 insertions(+) create mode 100644 B00/description.txt create mode 100644 B00/fsa_description.arg create mode 100644 B00/read.txt create mode 100644 B00/run.py create mode 100644 B00/test1.exp diff --git a/B00/description.txt b/B00/description.txt new file mode 100644 index 0000000..981efc2 --- /dev/null +++ b/B00/description.txt @@ -0,0 +1,8 @@ +Read a description of a deterministic finite-state automaton in the AT&T format +(without weights) from the file in the first argument. + +Read strings from the standard input. +If a string is accepted by the +automaton, write YES, otherwise- write NO. + +The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out diff --git a/B00/fsa_description.arg b/B00/fsa_description.arg new file mode 100644 index 0000000..5d98119 --- /dev/null +++ b/B00/fsa_description.arg @@ -0,0 +1,16 @@ +0 1 x +1 2 y +2 3 z +0 4 y +0 4 z +1 4 x +1 4 z +2 4 x +2 4 y +3 4 x +3 4 y +3 4 z +4 4 x +4 4 y +4 4 z +3 diff --git a/B00/read.txt b/B00/read.txt new file mode 100644 index 0000000..cb4d3cb --- /dev/null +++ b/B00/read.txt @@ -0,0 +1,2 @@ +windows +py .\run.py .\fsa_description.arg .\test1.in .\test1.out diff --git a/B00/run.py b/B00/run.py new file mode 100644 index 0000000..e074ccb --- /dev/null +++ b/B00/run.py @@ -0,0 +1,90 @@ +import sys + +# global fsa_description +# global inputWords +# global outputResult + +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('\t')) == 1: + return line[0], 0 + transition = line.strip().split('\t') + 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 == '3' else '0') + 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': + output.write("YES\n") + elif answersYN[i] == '0': + output.write("NO\n") + +print(answersYN) + + + +# +# import sys +# +# acceptingPos = None +# def readDescription(currentPos, charInput): +# with open("fsa_description.arg", 'r', encoding="utf-8") as descript: +# # global acceptingPos +# +# for line in descript: +# if line.strip().split('\t')==1: +# # acceptingPos = line[0] +# return line[0], 0 +# transition = line.strip().split('\t') +# +# if currentPos == transition[0] and charInput == transition[2]: +# return transition[1],1 +# return None, None +# +# # startPos, endPos, char = +# # if currentPos==startPos and charInput==char: +# # currentPos = endPos +# # return currentPos, 1 +# +# # return None, None +# +# +# +# answersYN='' +# with open("test1.in", 'r', encoding="utf-8") as inputString: +# currentPos=None +# for line in inputString: +# pos = '0' +# for char in line: +# +# if char == '\n': +# if pos == '3' : +# answersYN +='1' +# +# else: +# answersYN +='0' +# newPos, flag = readDescription(pos, char) +# if flag==1: +# pos = newPos +# +# +# print(answersYN) +# + diff --git a/B00/test1.exp b/B00/test1.exp new file mode 100644 index 0000000..1e23577 --- /dev/null +++ b/B00/test1.exp @@ -0,0 +1,9 @@ +NO +YES +NO +NO +NO +NO +NO +NO +NO