From 77de00fd23a6f61466d3f145da1a0919de4ba00c Mon Sep 17 00:00:00 2001 From: mxsgd Date: Wed, 3 Jan 2024 19:19:38 +0100 Subject: [PATCH] update --- .idea/djfz-2023.iml | 2 +- .idea/misc.xml | 2 +- TaskC00/run.py | 10 ++++++++++ TaskC03/run.py | 6 +++--- TaskC03/{nfsa.arg => test.arg} | 0 TaskE20/description.txt | 13 ++++++------- TaskE20/run.py | 4 ++-- TaskE42/run.py | 2 +- 8 files changed, 24 insertions(+), 15 deletions(-) rename TaskC03/{nfsa.arg => test.arg} (100%) diff --git a/.idea/djfz-2023.iml b/.idea/djfz-2023.iml index d0876a7..8388dbc 100644 --- a/.idea/djfz-2023.iml +++ b/.idea/djfz-2023.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e557d17..1ccab34 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/TaskC00/run.py b/TaskC00/run.py index 70fff48..0bea6c8 100644 --- a/TaskC00/run.py +++ b/TaskC00/run.py @@ -20,10 +20,20 @@ class FSA: else: self.transitions[state_from] = dict() self.transitions[state_from][symbol] = {state_to} + def get_final_state(self, string): + current_state = self.initial_state + for symbol in string: + current_state = self.transitions[current_state][symbol] + return current_state def add_final_state(self, state): self.final_states.add(state) + def accepts(self, string): + if self.get_final_state(string) in self.final_states: + return True + else: + return False fsa = FSA() diff --git a/TaskC03/run.py b/TaskC03/run.py index 2294861..401ab42 100644 --- a/TaskC03/run.py +++ b/TaskC03/run.py @@ -37,14 +37,14 @@ nfa = NFA() table = open(sys.argv[1]) for line in table: line = line.rstrip('\n') - if len(line.split('\t')) == 3: - a, b, c = line.split('\t') + if len(line.split(' ')) == 3: + a, b, c = line.split(' ') c = c.replace("'","") c = list(c) for x in c: nfa.add_transition(a, b, x) nfa.alphabet.add(x) - elif len(line.split('\t')) == 1: + elif len(line.split(' ')) == 1: nfa.add_final_state(line) else: assert False diff --git a/TaskC03/nfsa.arg b/TaskC03/test.arg similarity index 100% rename from TaskC03/nfsa.arg rename to TaskC03/test.arg diff --git a/TaskE20/description.txt b/TaskE20/description.txt index cfd24e5..9cd2938 100644 --- a/TaskE20/description.txt +++ b/TaskE20/description.txt @@ -15,16 +15,15 @@ can not use negation in the programming language if it is possible to express the same in regular expression). Wherever possible, use one regular expression. -Dla każdego napisu należy wydobyć zadany napis jest numerem telefonu. +Dla każdego napisu należy wskazać czy zadany napis jest numerem telefonu. Zakładamy, że numer telefonu składa się z dwóch cyfr opcjonalnie poprzedzonych zerem, po których następuje spacja i 7 cyfr w formacie -N-NNN-NNN. Jeśli napis nie spełnia podanych warunków, należy wypisać -"". +N-NNN-NNN. Jeśli napis spełnia podane warunki, należy wypisać +"yes", w przeciwnym wypadku "no". -For each string, extract a phone number. We assume, that the phone +For each string, indicate whether it is a phone number. We assume, that the phone number consists of two digits (optionally prefixed by zero), followed -by space and 7 digits in N-NNN-NNN format. If the string does -not fulfill the condition, print "". +by space and 7 digits in N-NNN-NNN format. If the string fulfills the condition, print "yes", otherwise "no". UWAGA! Zadanie przeznaczone dla studentów, których numer indeksu dzieli się przez 27 z resztą 20. @@ -33,4 +32,4 @@ Attention. The task is for students whose students id remainder of the division POINTS: 1 DEADLINE: 2023-12-10 23:59:59 -REMAINDER: 20/27 +REMAINDER: 20/27 \ No newline at end of file diff --git a/TaskE20/run.py b/TaskE20/run.py index 8f75f31..9e0d8cd 100644 --- a/TaskE20/run.py +++ b/TaskE20/run.py @@ -4,6 +4,6 @@ import re for line in sys.stdin: numbers = re.match(r'^(0?[0-9]{2}) (\d{1}-\d{3}-\d{3})$', line.replace("\n", ""), flags=re.IGNORECASE) if numbers: - print(numbers) + print('yes') else: - print("") \ No newline at end of file + print("no") \ No newline at end of file diff --git a/TaskE42/run.py b/TaskE42/run.py index 494856c..f603ffc 100644 --- a/TaskE42/run.py +++ b/TaskE42/run.py @@ -2,7 +2,7 @@ import sys import re for line in sys.stdin: - str = re.match(r'(NIE|NO).*[EO]{6,}.*!!!.*', line.replace("\n", ""), flags=re.IGNORECASE) + str = re.match(r'^N(IE|O).*[EO]{5,}.*!!!.*', line.replace("\n", ""), flags=re.IGNORECASE) if str: print('yes') else: