From d80adf4e0f1c3937ce2287ccf7ced772084cfb08 Mon Sep 17 00:00:00 2001 From: mxsgd Date: Sun, 17 Dec 2023 21:57:50 +0100 Subject: [PATCH] update --- .idea/djfz-2023.iml | 8 +++++++ TaskC06/run.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ TaskD01/run.py | 11 ++++++++++ TaskD02/run.py | 11 ++++++++++ TaskD03/run.py | 11 ++++++++++ TaskD04/run.py | 12 ++++++++++ 6 files changed, 106 insertions(+) create mode 100644 .idea/djfz-2023.iml create mode 100644 TaskC06/run.py create mode 100644 TaskD01/run.py create mode 100644 TaskD02/run.py create mode 100644 TaskD03/run.py create mode 100644 TaskD04/run.py diff --git a/.idea/djfz-2023.iml b/.idea/djfz-2023.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/djfz-2023.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/TaskC06/run.py b/TaskC06/run.py new file mode 100644 index 0000000..2294861 --- /dev/null +++ b/TaskC06/run.py @@ -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") \ No newline at end of file diff --git a/TaskD01/run.py b/TaskD01/run.py new file mode 100644 index 0000000..68f36ba --- /dev/null +++ b/TaskD01/run.py @@ -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) \ No newline at end of file diff --git a/TaskD02/run.py b/TaskD02/run.py new file mode 100644 index 0000000..1b190a1 --- /dev/null +++ b/TaskD02/run.py @@ -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) diff --git a/TaskD03/run.py b/TaskD03/run.py new file mode 100644 index 0000000..934cf26 --- /dev/null +++ b/TaskD03/run.py @@ -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) \ No newline at end of file diff --git a/TaskD04/run.py b/TaskD04/run.py new file mode 100644 index 0000000..ca48097 --- /dev/null +++ b/TaskD04/run.py @@ -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='')