zadania F
This commit is contained in:
parent
69b862a2d2
commit
b8ff9bedad
25
TaskF00/run.py
Normal file
25
TaskF00/run.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def substitute_digits(input_string):
|
||||||
|
def replace_digit(match):
|
||||||
|
digits = match.group()
|
||||||
|
replaced_digits = ''
|
||||||
|
for digit in digits:
|
||||||
|
if '0' <= digit <= '9':
|
||||||
|
replaced_digits += chr(ord('a') + int(digit))
|
||||||
|
else:
|
||||||
|
replaced_digits += digit
|
||||||
|
return replaced_digits
|
||||||
|
|
||||||
|
pattern = re.compile(r'\d{4}')
|
||||||
|
substituted_string = pattern.sub(replace_digit, input_string)
|
||||||
|
|
||||||
|
return substituted_string
|
||||||
|
|
||||||
|
|
||||||
|
file_path = 'simple.in'
|
||||||
|
with open(file_path, 'r', encoding = 'utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
line = line.rstrip('\n')
|
||||||
|
result = substitute_digits(line)
|
||||||
|
print(result)
|
10
TaskF01/run.py
Normal file
10
TaskF01/run.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def process_file(file_path):
|
||||||
|
with open(file_path, 'r',encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
modified_line = re.sub(r'\b(?:[A-Z]+\w*[a-z]+\w*|[a-z]+\w*[A-Z]+\w*)\b', lambda match: match.group(0).swapcase(), line)
|
||||||
|
print(modified_line, end='')
|
||||||
|
|
||||||
|
file_path = 'polish_wiki_excerpt.exp'
|
||||||
|
process_file(file_path)
|
23
TaskF02/run.py
Normal file
23
TaskF02/run.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def analyze_line(line):
|
||||||
|
result = re.findall(r'([a-ząćęłńóśźż])|([A-ZĄĆĘŁŃÓŚŹŻ])|(\d)|(\s)', line, flags=re.UNICODE)
|
||||||
|
|
||||||
|
lower_case_letters = [match[0] for match in result if match[0]]
|
||||||
|
upper_case_letters = [match[1] for match in result if match[1]]
|
||||||
|
digits = [match[2] for match in result if match[2]]
|
||||||
|
special_characters = [match[3] for match in result if match[3]]
|
||||||
|
|
||||||
|
result = f"{len(lower_case_letters)} {len(upper_case_letters)} {len(digits)} {len(special_characters)}"
|
||||||
|
return result
|
||||||
|
|
||||||
|
def process_file(file_path):
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
line = line.rstrip('\n')
|
||||||
|
if line:
|
||||||
|
result = analyze_line(line)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
file_path = 'simple.in'
|
||||||
|
process_file(file_path)
|
13
TaskF03/run.py
Normal file
13
TaskF03/run.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def process_line(line):
|
||||||
|
words = re.findall(r'\b(?:[a-ząćęłńóśźż]+\w*|[A-ZĄĆĘŁŃÓŚŹŻ]+\w*)\b', line, flags=re.UNICODE)
|
||||||
|
lowercase_words = [word for word in words if word[0].islower()]
|
||||||
|
uppercase_words = [word for word in words if word[0].isupper()]
|
||||||
|
return f"{len(lowercase_words)} {len(uppercase_words)}"
|
||||||
|
|
||||||
|
file_path = 'simple.in'
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
result = process_line(line.strip())
|
||||||
|
print(result)
|
22
TaskF04/run.py
Normal file
22
TaskF04/run.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def delete_second_digits(input_line):
|
||||||
|
regex = r'\b(\d+)\b'
|
||||||
|
numbers = re.findall(regex, input_line)
|
||||||
|
|
||||||
|
if len(numbers) > 1:
|
||||||
|
second_number = numbers[1]
|
||||||
|
input_line = re.sub(re.escape(second_number), '', input_line, 1)
|
||||||
|
|
||||||
|
return input_line
|
||||||
|
|
||||||
|
file_path = 'simple.in'
|
||||||
|
output_lines = []
|
||||||
|
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
modified_line = delete_second_digits(line)
|
||||||
|
output_lines.append(modified_line)
|
||||||
|
|
||||||
|
for line in output_lines:
|
||||||
|
print(line, end='')
|
@ -1,3 +1,6 @@
|
|||||||
Mam 2 jabłka i 35 banananów.
|
Mam 2 jabłka i 35 banananów.
|
||||||
Mam 2 jabłka i 35 banananów oraz 20 gruszek.
|
Mam 2 jabłka i 35 banananów oraz 20 gruszek.
|
||||||
Widziałem 2 bociany.
|
Widziałem 2 bociany.
|
||||||
|
2 35 209
|
||||||
|
12 34
|
||||||
|
532 234 234 324
|
15
TaskF05/run.py
Normal file
15
TaskF05/run.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def process_line(line):
|
||||||
|
words = re.findall(r'\w+', line)
|
||||||
|
if len(words) >= 3:
|
||||||
|
third_word = words[2]
|
||||||
|
replacement = 'x' * len(third_word)
|
||||||
|
line = re.sub(r'\b' + re.escape(third_word) + r'\b', replacement, line)
|
||||||
|
|
||||||
|
return line
|
||||||
|
|
||||||
|
with open('simple.in', 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
processed_line = process_line(line)
|
||||||
|
print(processed_line, end='')
|
Loading…
Reference in New Issue
Block a user