Fixed C01-03

This commit is contained in:
IgnBys 2023-11-25 23:43:26 +01:00
parent fd6c90a06a
commit 7e83b40edd
3 changed files with 70 additions and 52 deletions

View File

@ -2,6 +2,14 @@ import sys
sys.setrecursionlimit(5000) 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): def write_answer(answer):
with open(output_file, 'a') as file: with open(output_file, 'a') as file:
file.write(answer+'\n') file.write(answer+'\n')
@ -23,33 +31,28 @@ def line_checking(row, position):
stack.append((help_row[1:], element_in_next_position_array)) stack.append((help_row[1:], element_in_next_position_array))
return False return False
def find_next_position(position, character): def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table: take_all_possible_positions = []
take_all_possible_positions = [] for row_used_table in arg:
for row_used_table in readed_used_table: if len(row_used_table) != 1:
line = row_used_table.strip().split(' ') if position == row_used_table[0] and character == row_used_table[2]:
if len(line) != 1: take_all_possible_positions.append(row_used_table[1])
if position == line[0] and character == line[2]:
take_all_possible_positions.append(line[1])
return take_all_possible_positions return take_all_possible_positions
def what_is_the_ended_positions(): def what_is_the_ended_positions():
array = [] array = []
with open(used_table, 'r') as file: for row in arg:
for row in file: if len(row) == 1:
line = row.strip().split('\t') array += row
if len(line) == 1: return array
array += line
return array
# used_table = 'test.arg' # used_table = 'test.arg'
# input_file = 'test.in' # input_file = 'test.in'
# output_file = 'test.out' # output_file = 'test.out'
used_table = sys.argv[1] # used_table = sys.argv[1]
input_file = sys.argv[2] input_file = sys.argv[1]
output_file = sys.argv[3] output_file = sys.argv[2]
with open(output_file, 'w') as readed_output_file: with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file: with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file: for row_input_file in readed_input_file:

View File

@ -2,6 +2,16 @@ import sys
sys.setrecursionlimit(5000) 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): def write_answer(answer):
with open(output_file, 'a') as file: with open(output_file, 'a') as file:
file.write(answer+'\n') file.write(answer+'\n')
@ -25,31 +35,27 @@ def line_checking(row, position):
return False return False
def find_next_position(position, character): def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table: take_all_possible_positions = []
take_all_possible_positions = [] for row_used_table in arg:
for row_used_table in readed_used_table: if len(row_used_table) != 1:
line = row_used_table.strip().split(' ') if position == row_used_table[0] and character == row_used_table[2]:
if len(line) != 1: take_all_possible_positions.append(row_used_table[1])
if position == line[0] and character == line[2]:
take_all_possible_positions.append(line[1])
return take_all_possible_positions return take_all_possible_positions
def what_is_the_ended_positions(): def what_is_the_ended_positions():
array = [] array = []
with open(used_table, 'r') as file: for row in arg:
for row in file: if len(row) == 1:
line = row.strip().split('\t') array += row
if len(line) == 1: return array
array += line
return array
# used_table = 'test.arg' # used_table = 'test.arg'
# input_file = 'test.in' # input_file = 'test.in'
# output_file = 'test.out' # output_file = 'test.out'
used_table = sys.argv[1] # used_table = sys.argv[1]
input_file = sys.argv[2] input_file = sys.argv[1]
output_file = sys.argv[3] output_file = sys.argv[2]
with open(output_file, 'w') as readed_output_file: with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file: with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file: for row_input_file in readed_input_file:

View File

@ -2,6 +2,19 @@ import sys
sys.setrecursionlimit(5000) 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): def write_answer(answer):
with open(output_file, 'a') as file: with open(output_file, 'a') as file:
file.write(answer+'\n') file.write(answer+'\n')
@ -25,31 +38,27 @@ def line_checking(row, position):
return False return False
def find_next_position(position, character): def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table: take_all_possible_positions = []
take_all_possible_positions = [] for row_used_table in arg:
for row_used_table in readed_used_table: if len(row_used_table) != 1:
line = row_used_table.strip().split(' ') if position == row_used_table[0] and character == row_used_table[2]:
if len(line) != 1: take_all_possible_positions.append(row_used_table[1])
if position == line[0] and character == line[2]:
take_all_possible_positions.append(line[1])
return take_all_possible_positions return take_all_possible_positions
def what_is_the_ended_positions(): def what_is_the_ended_positions():
array = [] array = []
with open(used_table, 'r') as file: for row in arg:
for row in file: if len(row) == 1:
line = row.strip().split('\t') array += row
if len(line) == 1: return array
array += line
return array
# used_table = 'test.arg' # used_table = 'test.arg'
# input_file = 'test.in' # input_file = 'test.in'
# output_file = 'test.out' # output_file = 'test.out'
used_table = sys.argv[1] # used_table = sys.argv[1]
input_file = sys.argv[2] input_file = sys.argv[1]
output_file = sys.argv[3] output_file = sys.argv[2]
with open(output_file, 'w') as readed_output_file: with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file: with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file: for row_input_file in readed_input_file: