update
This commit is contained in:
parent
5e9c631528
commit
d80adf4e0f
8
.idea/djfz-2023.iml
Normal file
8
.idea/djfz-2023.iml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
53
TaskC06/run.py
Normal file
53
TaskC06/run.py
Normal file
@ -0,0 +1,53 @@
|
||||
import sys
|
||||
|
||||
class NFA:
|
||||
def __init__(self):
|
||||
self.initial_state = '0'
|
||||
self.final_states = set()
|
||||
|
||||
self.transitions = dict()
|
||||
self.alphabet = set()
|
||||
|
||||
def add_transition(self, state_from, state_to, symbol):
|
||||
|
||||
if state_from in self.transitions.keys():
|
||||
if symbol not in self.transitions[state_from].keys():
|
||||
self.transitions[state_from][symbol] = {state_to}
|
||||
else:
|
||||
self.transitions[state_from][symbol] |= {state_to}
|
||||
else:
|
||||
self.transitions[state_from] = dict()
|
||||
self.transitions[state_from][symbol] = {state_to}
|
||||
|
||||
def add_final_state(self, state):
|
||||
self.final_states.add(state)
|
||||
|
||||
def get_final_states(self, string):
|
||||
current_states = {self.initial_state}
|
||||
for symbol in string:
|
||||
current_states = {state for current_state in current_states for state in self.transitions.get(current_state, {}).get(symbol, set())}
|
||||
return current_states
|
||||
|
||||
def accepts(self, string):
|
||||
return any(final_state in self.final_states for final_state in self.get_final_states(string))
|
||||
|
||||
|
||||
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')
|
||||
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:
|
||||
nfa.add_final_state(line)
|
||||
else:
|
||||
assert False
|
||||
|
||||
for line in sys.stdin:
|
||||
print("YES" if nfa.accepts(line.strip()) else "NO")
|
11
TaskD01/run.py
Normal file
11
TaskD01/run.py
Normal file
@ -0,0 +1,11 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def re_find_hamlet(input):
|
||||
for _, l in enumerate(input, start=1):
|
||||
if re.search(r'\bHamlet\b', l):
|
||||
print(l.strip())
|
||||
|
||||
|
||||
re_find_hamlet(sys.stdin)
|
11
TaskD02/run.py
Normal file
11
TaskD02/run.py
Normal file
@ -0,0 +1,11 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def pies(input):
|
||||
for _, l in enumerate(input, start=1):
|
||||
if re.search(r'\bpies\b', l, flags=re.IGNORECASE):
|
||||
print(l.strip())
|
||||
|
||||
|
||||
pies(sys.stdin)
|
11
TaskD03/run.py
Normal file
11
TaskD03/run.py
Normal file
@ -0,0 +1,11 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def pog_champ(input):
|
||||
for _, l in enumerate(input, start=1):
|
||||
if re.search(r'19\d{2} r\.', l):
|
||||
print(l.strip())
|
||||
|
||||
|
||||
pog_champ(sys.stdin)
|
12
TaskD04/run.py
Normal file
12
TaskD04/run.py
Normal file
@ -0,0 +1,12 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def find_numbers(s):
|
||||
return re.compile(r'\d+').findall(s)
|
||||
|
||||
input = sys.stdin.read().splitlines()
|
||||
|
||||
for l in input:
|
||||
r = find_numbers(l)
|
||||
print(f"{' '.join(r)}\n" if r else '', end='')
|
Loading…
Reference in New Issue
Block a user