This commit is contained in:
s464933 2024-01-29 23:18:03 +01:00
parent d84cd90855
commit 41b58e6808
7 changed files with 88800 additions and 336 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,13 +1,29 @@
import re
import sys
import re, sys
def change_chars_in_string(string:str, new_chars:str, index:int) -> str:
new_chars_size = len(new_chars)
return string[:index] + new_chars + string[index+new_chars_size:]
def zad_01(line:str) -> str:
uppercase_pattern = "[A-ZĄĆĘŁŃÓŚŹŻ]"
lowercase_pattern = "[a-ząćęłńóśźż]"
matches = re.finditer('\w+',line)
for match in matches:
match_word = match.group()
if re.search(uppercase_pattern,match_word) and re.search(lowercase_pattern,match_word):
new_word = ""
for m in match_word:
if re.search(uppercase_pattern,m):
new_word += m.lower()
elif re.search(lowercase_pattern,m):
new_word += m.upper()
line = change_chars_in_string(line,new_word,match.start())
return line
def switch_case(m):
return m.group(0).swapcase()
if __name__ == "__main__":
for _, l in enumerate(sys.stdin, start=1):
p = re.compile(r'\b(?:[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]|[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+)\w*\b')
r = p.sub(switch_case, l)
print(r, end="")
for line in sys.stdin:
line = line.rstrip("\n")
line = zad_01(line)
print(line)

32
TaskG00/run.py Normal file
View File

@ -0,0 +1,32 @@
import sys
import re2
import csv
def load_surnames_from_csv(filename):
with open(filename, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
surnames = [row[0].strip().lower() for row in reader]
return surnames
def build_patterns(surnames):
patterns = [re2.compile(surname) for surname in surnames]
return patterns
def contains_lowercase_surname(line, patterns):
lowercase_line = line.lower()
return any(pattern.search(lowercase_line) for pattern in patterns)
def main():
male_surnames = load_surnames_from_csv('TaskG00/male_surnames.csv')
female_surnames = load_surnames_from_csv('TaskG00/female_surnames.csv')
all_surnames = list(set(female_surnames + male_surnames))
all_surnames.sort()
patterns = build_patterns(all_surnames)
for line in sys.stdin:
if contains_lowercase_surname(line, patterns):
print(line, end="")
main()

0
TaskG02/run.py Normal file
View File

50000
TaskG03/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

16
TaskG03/run.py Normal file
View File

@ -0,0 +1,16 @@
import re2
import sys
def load_surnames(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return [line.strip() for line in file]
polish_surnames = load_surnames('nazwiska.txt')
setting = re2.Options()
setting.max_mem = 1 << 30
pattern = re2.compile('|'.join(polish_surnames), setting)
for line in sys.stdin:
if pattern.search(line.lower()):
print(line.strip())

View File

@ -71,7 +71,7 @@ def does_task_match_index(dir, index):
def get_tasks(index):
all_tasks = Path('.').glob('TaskG05')
all_tasks = Path('.').glob('TaskG00')
return [task for task in all_tasks if does_task_match_index(task, index)]