This commit is contained in:
mxsgd 2024-01-03 19:19:38 +01:00
parent 2e63e7e82c
commit 77de00fd23
8 changed files with 24 additions and 15 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.8" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

View File

@ -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()

View File

@ -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

View File

@ -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ć
"<NONE>".
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 "<NONE>".
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

View File

@ -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("<NONE>")
print("no")

View File

@ -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: