D01 and other fixes

This commit is contained in:
IgnBys 2023-11-27 22:38:20 +01:00
parent 42e3416d3f
commit c5d488229f
7 changed files with 87 additions and 34 deletions

View File

@ -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
else:
checkWord += i
if i == '\n':
allLine = ''
for letter in row:
if checkWord != '':
print(checkWord)
if letter == checkNumber(letter):
checkWord += letter
else:
allLine += checkWord
allLine += ' '
checkWord = ''
lastCharacter = i
else:
if letter == checkNumber(letter):
checkWord += letter
if letter == '\n':
if allLine != '':
print(allLine)
allLine = ''

View File

@ -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])

View File

@ -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)
main_function(pattern, input_file, output_file)

View File

@ -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)
main_function(pattern, input_file, output_file)

View File

@ -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)
# 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)

41
TaskD04/run.py Normal file
View File

@ -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)

4
TaskD04/simple.out Normal file
View File

@ -0,0 +1,4 @@
34234 34 5
34535
34
1992 1999