This commit is contained in:
Adam 2020-12-06 18:07:42 +01:00
parent 086a27dfa3
commit 08f802f8a9
5 changed files with 30 additions and 33 deletions

View File

@ -1,38 +1,19 @@
import re
import sys
import re
def repl(char):
x = char.group(0)
output_str = ""
for c in x:
c = c.swapcase()
output_str += c
return output_str
def replaceLetter(words):
result = ''
for i in words.group(0):
if re.search(r'[a-ząćęłńóśźż]', i):
result += i.upper()
elif re.search(r'[A-ZĄĆĘŁŃÓŚŹŻ]', i):
result += i.lower()
else:
result += i
return result
pattern = re.compile(r"\b[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]+\b|\b[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+\b")
# f = open("polish_wiki_excerpt.in", "r")
def change_line(word_list, curr_line):
for word in word_list:
curr_line = curr_line.replace(word, word.swapcase())
return curr_line.rstrip('\n')
# for line in open("./polish_wiki_excerpt.in", encoding="utf8"):
for line in sys.stdin:
found_words = re.findall(pattern, line)
out = change_line(found_words, line)
if out:
print(out)
searchRe = re.sub(r'[a-ząćęłńóśźż]+\w*[A-ZĄĆĘŁŃÓŚŹŻ]+\w*|[A-ZĄĆĘŁŃÓŚŹŻ]+\w*[a-ząćęłńóśźż]+\w*', replaceLetter, line)
print(searchRe, end='')

View File

@ -2,7 +2,7 @@ import re
import sys
for line in sys.stdin:
line = re.sub(r'(\D*)([0-9]+)(\D+)([0-9]+).*', r'\1\2\3\5', line)
line = re.sub(r'(\D*)([0-9]+)(\D+)([0-9]+)(.*)', r'\1\2\3\5', line, 1)
sys.stdout.write(line)

0
TaskD05/Makefile Normal file
View File

2
TaskD05/run Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
python TaskD05/run.py "$@"

14
TaskD05/run.py Normal file
View File

@ -0,0 +1,14 @@
import sys
import re
def replaceLetters(words):
result = words.group(1)
for i in words.group(2):
result += 'x'
return result
for line in sys.stdin:
replaceXin3rdPos = re.sub(r'^(\W*\w+\W+\w+\W+)(\w+)', replaceLetters, line, 1)
print(replaceXin3rdPos, end='')