From 08f802f8a9a34e2a846ba43e938184aa8d6c2e82 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 6 Dec 2020 18:07:42 +0100 Subject: [PATCH] all --- TaskD01/run.py | 45 +++++++++++++-------------------------------- TaskD04/run.py | 2 +- TaskD05/Makefile | 0 TaskD05/run | 2 ++ TaskD05/run.py | 14 ++++++++++++++ 5 files changed, 30 insertions(+), 33 deletions(-) create mode 100644 TaskD05/Makefile create mode 100644 TaskD05/run create mode 100644 TaskD05/run.py diff --git a/TaskD01/run.py b/TaskD01/run.py index 6cdd2f0..6dc8783 100644 --- a/TaskD01/run.py +++ b/TaskD01/run.py @@ -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='') \ No newline at end of file diff --git a/TaskD04/run.py b/TaskD04/run.py index 7aaa4c8..237075a 100644 --- a/TaskD04/run.py +++ b/TaskD04/run.py @@ -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) diff --git a/TaskD05/Makefile b/TaskD05/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/TaskD05/run b/TaskD05/run new file mode 100644 index 0000000..dced280 --- /dev/null +++ b/TaskD05/run @@ -0,0 +1,2 @@ +#!/bin/bash +python TaskD05/run.py "$@" \ No newline at end of file diff --git a/TaskD05/run.py b/TaskD05/run.py new file mode 100644 index 0000000..ff6bfc7 --- /dev/null +++ b/TaskD05/run.py @@ -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='') \ No newline at end of file