This commit is contained in:
Wojtek 2024-01-20 16:39:21 +01:00
parent fe915f67c3
commit 36127d0d12
6 changed files with 95 additions and 0 deletions

14
TaskF00/run.py Normal file
View File

@ -0,0 +1,14 @@
import re
def substitute(file_path):
def replace(match):
return ''.join(chr(ord('a') + int(digit)) for digit in match.group(0))
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
substituted_line = re.sub(r'\b\d{4}\b', replace, line.strip())
print(substituted_line)
file_path = 'TaskF00/simple.in'
substitute(file_path)

15
TaskF01/run.py Normal file
View File

@ -0,0 +1,15 @@
import re
def swap(file_path):
pattern = r'\b(?=\w*[a-ząćęłńóśźż])(?=\w*[A-ZĄĆĘŁŃÓŚŹŻ])\w+\b'
def swap_case(match):
return match.group(0).swapcase()
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
swapped_line = re.sub(pattern, swap_case, line)
print(swapped_line, end='')
file_path = 'TaskF01/simple.in'
swap(file_path)

17
TaskF02/run.py Normal file
View File

@ -0,0 +1,17 @@
import re
def count_types(file_path):
lowercase_pattern = r'[a-ząćęłńóśźż]'
uppercase_pattern = r'[A-ZĄĆĘŁŃÓŚŹŻ]'
digit_pattern = r'\d'
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
a = len(re.findall(lowercase_pattern, line))
b = len(re.findall(uppercase_pattern, line))
c = len(re.findall(digit_pattern, line))
d = len(line) - a - b - c - line.count('\n')
print(f"{a} {b} {c} {d}")
file_path = 'TaskF02/simple.in'
count_types(file_path)

14
TaskF03/run.py Normal file
View File

@ -0,0 +1,14 @@
import re
def count(file_path):
lowercase= r'\b[a-ząćęłńóśźż]\w*'
uppercase = r'\b[A-ZĄĆĘŁŃÓŚŹŻ]\w*'
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
lowercase_count = len(re.findall(lowercase, line))
uppercase_count = len(re.findall(uppercase, line))
print(f"{lowercase_count} {uppercase_count}")
file_path = 'TaskF03/simple.in'
count(file_path)

17
TaskF04/run.py Normal file
View File

@ -0,0 +1,17 @@
import re
def delete(file_path):
digit_pattern = r'\d+'
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
matches = list(re.finditer(digit_pattern, line))
if len(matches) >= 2:
start, end = matches[1].span()
line = line[:start] + line[end:]
print(line, end='')
file_path = 'TaskF04/simple.in'
delete(file_path)

18
TaskF05/run.py Normal file
View File

@ -0,0 +1,18 @@
import re
def replace(file_path):
word_pattern = r'\b\w+\b'
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
words = list(re.finditer(word_pattern, line))
if len(words) >= 3:
start, end = words[2].span()
word_length = end - start
line = line[:start] + 'x' * word_length + line[end:]
print(line, end='')
file_path = 'TaskF05/simple.in'
replace(file_path)