update
This commit is contained in:
parent
2e63e7e82c
commit
77de00fd23
@ -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>
|
@ -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>
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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")
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user