From 7e83b40edd348165a1988f8c9452d3821ba449f2 Mon Sep 17 00:00:00 2001 From: IgnBys Date: Sat, 25 Nov 2023 23:43:26 +0100 Subject: [PATCH] Fixed C01-03 --- TaskC01/run.py | 39 +++++++++++++++++++++------------------ TaskC02/run.py | 40 +++++++++++++++++++++++----------------- TaskC03/run.py | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 70 insertions(+), 52 deletions(-) diff --git a/TaskC01/run.py b/TaskC01/run.py index 6ba1fbb..19631f1 100644 --- a/TaskC01/run.py +++ b/TaskC01/run.py @@ -2,6 +2,14 @@ import sys sys.setrecursionlimit(5000) +arg = [['0','0','a'], + ['0', '0' ,'b'], + ['0' ,'0' ,'c'], + ['0', '1', 'b'], + ['1', '2', 'a'], + ['1', '2', 'b'], + ['1', '2','c'], + '2'] def write_answer(answer): with open(output_file, 'a') as file: file.write(answer+'\n') @@ -23,33 +31,28 @@ def line_checking(row, position): stack.append((help_row[1:], element_in_next_position_array)) return False - def find_next_position(position, character): - with open(used_table, 'r') as readed_used_table: - take_all_possible_positions = [] - for row_used_table in readed_used_table: - line = row_used_table.strip().split(' ') - if len(line) != 1: - if position == line[0] and character == line[2]: - take_all_possible_positions.append(line[1]) + take_all_possible_positions = [] + for row_used_table in arg: + if len(row_used_table) != 1: + if position == row_used_table[0] and character == row_used_table[2]: + take_all_possible_positions.append(row_used_table[1]) - return take_all_possible_positions + return take_all_possible_positions def what_is_the_ended_positions(): array = [] - with open(used_table, 'r') as file: - for row in file: - line = row.strip().split('\t') - if len(line) == 1: - array += line - return array + for row in arg: + if len(row) == 1: + array += row + return array # used_table = 'test.arg' # input_file = 'test.in' # output_file = 'test.out' -used_table = sys.argv[1] -input_file = sys.argv[2] -output_file = sys.argv[3] +# used_table = sys.argv[1] +input_file = sys.argv[1] +output_file = sys.argv[2] with open(output_file, 'w') as readed_output_file: with open(input_file, 'r') as readed_input_file: for row_input_file in readed_input_file: diff --git a/TaskC02/run.py b/TaskC02/run.py index 6ba1fbb..6869d84 100644 --- a/TaskC02/run.py +++ b/TaskC02/run.py @@ -2,6 +2,16 @@ import sys sys.setrecursionlimit(5000) +arg = [['0', '0', 'a'], +['0', '0', 'b'], +['0' ,'0', 'c'], +['0', '1', 'a'], +['1','2', 'b'], +['2', '0', 'a'], +['2' ,'0', 'b'], +['2', '0', 'c'], +'2'] + def write_answer(answer): with open(output_file, 'a') as file: file.write(answer+'\n') @@ -25,31 +35,27 @@ def line_checking(row, position): return False def find_next_position(position, character): - with open(used_table, 'r') as readed_used_table: - take_all_possible_positions = [] - for row_used_table in readed_used_table: - line = row_used_table.strip().split(' ') - if len(line) != 1: - if position == line[0] and character == line[2]: - take_all_possible_positions.append(line[1]) + take_all_possible_positions = [] + for row_used_table in arg: + if len(row_used_table) != 1: + if position == row_used_table[0] and character == row_used_table[2]: + take_all_possible_positions.append(row_used_table[1]) - return take_all_possible_positions + return take_all_possible_positions def what_is_the_ended_positions(): array = [] - with open(used_table, 'r') as file: - for row in file: - line = row.strip().split('\t') - if len(line) == 1: - array += line - return array + for row in arg: + if len(row) == 1: + array += row + return array # used_table = 'test.arg' # input_file = 'test.in' # output_file = 'test.out' -used_table = sys.argv[1] -input_file = sys.argv[2] -output_file = sys.argv[3] +# used_table = sys.argv[1] +input_file = sys.argv[1] +output_file = sys.argv[2] with open(output_file, 'w') as readed_output_file: with open(input_file, 'r') as readed_input_file: for row_input_file in readed_input_file: diff --git a/TaskC03/run.py b/TaskC03/run.py index 6ba1fbb..7ea5121 100644 --- a/TaskC03/run.py +++ b/TaskC03/run.py @@ -2,6 +2,19 @@ import sys sys.setrecursionlimit(5000) +arg = [['0' ,'0' ,'b'], +['0', '0', 'c'], +['0', '1', 'a'], +['1', '1', 'a'], +['1', '2', 'b'], +['2', '1', 'a'], +['2', '3', 'c'], +['3', '3', 'a'], +['3', '3', 'b'], +['3', '3', 'c'], +['2', '0', 'b'], +['1', '0', 'c'], +'3'] def write_answer(answer): with open(output_file, 'a') as file: file.write(answer+'\n') @@ -25,31 +38,27 @@ def line_checking(row, position): return False def find_next_position(position, character): - with open(used_table, 'r') as readed_used_table: - take_all_possible_positions = [] - for row_used_table in readed_used_table: - line = row_used_table.strip().split(' ') - if len(line) != 1: - if position == line[0] and character == line[2]: - take_all_possible_positions.append(line[1]) + take_all_possible_positions = [] + for row_used_table in arg: + if len(row_used_table) != 1: + if position == row_used_table[0] and character == row_used_table[2]: + take_all_possible_positions.append(row_used_table[1]) - return take_all_possible_positions + return take_all_possible_positions def what_is_the_ended_positions(): array = [] - with open(used_table, 'r') as file: - for row in file: - line = row.strip().split('\t') - if len(line) == 1: - array += line - return array + for row in arg: + if len(row) == 1: + array += row + return array # used_table = 'test.arg' # input_file = 'test.in' # output_file = 'test.out' -used_table = sys.argv[1] -input_file = sys.argv[2] -output_file = sys.argv[3] +# used_table = sys.argv[1] +input_file = sys.argv[1] +output_file = sys.argv[2] with open(output_file, 'w') as readed_output_file: with open(input_file, 'r') as readed_input_file: for row_input_file in readed_input_file: