Add Task F05
This commit is contained in:
parent
db3bfc8c32
commit
b620c05dd5
22
TaskF05/description.txt
Normal file
22
TaskF05/description.txt
Normal file
@ -0,0 +1,22 @@
|
||||
Napisać program, który wczytuje kolejne wiersze ze standardowego
|
||||
wejścia i analizuje każdy wiersz (bez znaku końca wiersza). Należy w
|
||||
jak największym stopniu wykorzystać wyrażenia regularne (np. nie wolno
|
||||
użyć negacji jako operacji w danym języku programowania, jeśli da się
|
||||
to wyrazić w samym wyrażeniu regularnym). Tam, gdzie to możliwe należy
|
||||
użyć pojedynczego wyrażenia regularnego.
|
||||
|
||||
Write a program, which loads consecutive lines from standard input
|
||||
and analyze every line (with no newline character). You should
|
||||
use regular expressions to the greatest extent possible (e.g. you
|
||||
can not use negation in the programming language if it is
|
||||
possible to express the same in regular expression). Wherever possible,
|
||||
use one regular expression.
|
||||
|
||||
Write the input line with the third word changed to "xxx" string.
|
||||
The number of "x" in the "xxx" string should be the same as the
|
||||
the number of characters in the input string.
|
||||
In this task, a word means a string of "\w" metacharacters.
|
||||
|
||||
|
||||
POINTS: 2
|
||||
DEADLINE: 2024-01-07 23:59:59
|
21
TaskF05/run.py
Normal file
21
TaskF05/run.py
Normal file
@ -0,0 +1,21 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
def replace_third_word(match):
|
||||
if match.group(2):
|
||||
replacement = 'x' * len(match.group(2))
|
||||
return f"{match.group(1)}{replacement}{match.group(3)}"
|
||||
else:
|
||||
return match.group(0)
|
||||
|
||||
def replace_third_word_in_line(line):
|
||||
|
||||
pattern = re.compile(r'((?:\b\w+\b\s+){2})(\b\w+\b)(.*)')
|
||||
replaced_line = pattern.sub(replace_third_word, line)
|
||||
|
||||
return replaced_line
|
||||
|
||||
|
||||
for line in sys.stdin:
|
||||
output_line = replace_third_word_in_line(line.strip())
|
||||
sys.stdout.write(output_line + '\n')
|
2
TaskF05/simple.exp
Normal file
2
TaskF05/simple.exp
Normal file
@ -0,0 +1,2 @@
|
||||
Mam 2 xxxxxx i 35 banananów.
|
||||
Widziałem 2 xxxxxxx.
|
2
TaskF05/simple.in
Normal file
2
TaskF05/simple.in
Normal file
@ -0,0 +1,2 @@
|
||||
Mam 2 jabłka i 35 banananów.
|
||||
Widziałem 2 bociany.
|
2
TaskF05/simple.out
Normal file
2
TaskF05/simple.out
Normal file
@ -0,0 +1,2 @@
|
||||
Mam 2 xxxxxx i 35 banananów.
|
||||
Widziałem 2 xxxxxxx.
|
Loading…
Reference in New Issue
Block a user