diff --git a/TaskA04/run.py b/TaskA04/run.py index b881cc1..863d5b1 100644 --- a/TaskA04/run.py +++ b/TaskA04/run.py @@ -1,17 +1,18 @@ +import sys -def checkNumber(i): - if (i == '0' - or i == '1' - or i == '2' - or i == '3' - or i == '4' - or i == '5' - or i == '6' - or i == '7' - or i == '8' - or i == '9'): - return i +def checkNumber(letter): + if (letter == '0' + or letter == '1' + or letter == '2' + or letter == '3' + or letter == '4' + or letter == '5' + or letter == '6' + or letter == '7' + or letter == '8' + or letter == '9'): + return letter else: return None def openFile(fileName): @@ -19,18 +20,25 @@ def openFile(fileName): for row in file: lastCharacter = '' checkWord ='' - for i in row: - if i == checkNumber(i): - if lastCharacter != checkNumber(lastCharacter): - checkWord += ' ' - checkWord += i + allLine = '' + + for letter in row: + if checkWord != '': + if letter == checkNumber(letter): + checkWord += letter else: - checkWord += i - if i == '\n': - if checkWord != '': - print(checkWord) + allLine += checkWord + allLine += ' ' checkWord = '' - lastCharacter = i + else: + if letter == checkNumber(letter): + checkWord += letter + + if letter == '\n': + if allLine != '': + print(allLine) + allLine = '' + diff --git a/TaskC06/run.py b/TaskC06/run.py index 6b35197..e0ff982 100644 --- a/TaskC06/run.py +++ b/TaskC06/run.py @@ -12,7 +12,7 @@ def run_automaton(file_path, end_positions, output_file): lines = file.readlines() for line in lines: - if line.strip(): # Пропускаем пустые строки + if line.strip(): parts = line.split() state_from = int(parts[0]) diff --git a/TaskD01/run.py b/TaskD01/run.py index 38fcb59..778b93f 100644 --- a/TaskD01/run.py +++ b/TaskD01/run.py @@ -5,7 +5,7 @@ def write_answer(row, ouput_file): file.write(row) -def find_hamlet(pattern, input_file, output_file): +def main_function(pattern, input_file, output_file): with open(output_file, "w", encoding="utf-8") as output_file1: with open(input_file, "r", encoding="utf-8") as file: for row in file: @@ -13,9 +13,9 @@ def find_hamlet(pattern, input_file, output_file): if re.search(pattern, help_row): write_answer(row, output_file) -pattern = re.compile(r'hamlet', re.IGNORECASE) +pattern = re.compile(r'Hamlet') # output_file ='simple.out' # input_file = 'simple.in' input_file = sys.argv[1] output_file = sys.argv[2] -find_hamlet(pattern, input_file, output_file) \ No newline at end of file +main_function(pattern, input_file, output_file) \ No newline at end of file diff --git a/TaskD02/run.py b/TaskD02/run.py index 0802502..19cb061 100644 --- a/TaskD02/run.py +++ b/TaskD02/run.py @@ -5,7 +5,7 @@ def write_answer(row, ouput_file): file.write(row) -def find_hamlet(pattern, input_file, output_file): +def main_function(pattern, input_file, output_file): with open(output_file, "w", encoding="utf-8") as output_file1: with open(input_file, "r", encoding="utf-8") as file: for row in file: @@ -18,4 +18,4 @@ pattern = re.compile(r'(?:^|\s)pies(?:\s|$)', re.IGNORECASE) # input_file = 'simple.in' input_file = sys.argv[1] output_file = sys.argv[2] -find_hamlet(pattern, input_file, output_file) \ No newline at end of file +main_function(pattern, input_file, output_file) \ No newline at end of file diff --git a/TaskD03/run.py b/TaskD03/run.py index ac801a1..0b3a2cf 100644 --- a/TaskD03/run.py +++ b/TaskD03/run.py @@ -5,7 +5,7 @@ def write_answer(row, ouput_file): file.write(row) -def find_hamlet(pattern, input_file, output_file): +def main_function(pattern, input_file, output_file): with open(output_file, "w", encoding="utf-8") as output_file1: with open(input_file, "r", encoding="utf-8") as file: for row in file: @@ -16,8 +16,8 @@ def find_hamlet(pattern, input_file, output_file): # pattern = re.compile(r'(?:^|\s)pies(?:\s|$)', re.IGNORECASE) pattern = re.compile(r'.*\b(?:19[0-9]{2}) r\.', re.IGNORECASE) -output_file ='polish_wiki_excerpt.in.out' -input_file = 'polish_wiki_excerpt.in' -# input_file = sys.argv[1] -# output_file = sys.argv[2] -find_hamlet(pattern, input_file, output_file) \ No newline at end of file +# output_file ='polish_wiki_excerpt.in.out' +# input_file = 'polish_wiki_excerpt.in' +input_file = sys.argv[1] +output_file = sys.argv[2] +main_function(pattern, input_file, output_file) \ No newline at end of file diff --git a/TaskD04/run.py b/TaskD04/run.py new file mode 100644 index 0000000..9827b5d --- /dev/null +++ b/TaskD04/run.py @@ -0,0 +1,41 @@ +import re +import sys +def write_answer(row, ouput_file,character): + with open(ouput_file, "a", encoding="utf-8") as file: + file.write(row+character) + + +def main_function(pattern, input_file, output_file): + with open(output_file, "w", encoding="utf-8") as output_file1: + with open(input_file, "r", encoding="utf-8") as file: + for row in file: + checkWord = '' + allLine = '' + for letter in row: + if checkWord != '': + if re.search(pattern, letter): + checkWord += letter + else: + allLine += checkWord + allLine += ' ' + write_answer(checkWord, output_file, ' ') + checkWord = '' + + else: + if re.search(pattern, letter): + checkWord += letter + + if letter == '\n': + if allLine != '': + write_answer('', output_file, '\n') + allLine = '' + + +# pattern = re.compile(r'(?:^|\s)pies(?:\s|$)', re.IGNORECASE) +pattern = r'\d+' + +# output_file ='simple.out' +# input_file = 'simple.in' +input_file = sys.argv[1] +output_file = sys.argv[2] +main_function(pattern, input_file, output_file) \ No newline at end of file diff --git a/TaskD04/simple.out b/TaskD04/simple.out new file mode 100644 index 0000000..13c2821 --- /dev/null +++ b/TaskD04/simple.out @@ -0,0 +1,4 @@ +34234 34 5 +34535 +34 +1992 1999