TaskC04
This commit is contained in:
parent
2eed53581b
commit
8c52521f2b
@ -1,10 +1,10 @@
|
|||||||
NO
|
TRUE a
|
||||||
NO
|
FALSE aa
|
||||||
NO
|
TRUE aaa
|
||||||
NO
|
TRUE abc
|
||||||
NO
|
TRUE aaabc
|
||||||
NO
|
FALSE aaabcd
|
||||||
NO
|
FALSE aabc
|
||||||
NO
|
FALSE abd
|
||||||
NO
|
TRUE ad
|
||||||
NO
|
FALSE aad
|
||||||
|
@ -1,38 +1,42 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.setrecursionlimit(5000)
|
def write_answer(answer, row):
|
||||||
|
|
||||||
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+' '+row)
|
||||||
|
|
||||||
def line_checking(row, position):
|
def line_checking(row, position):
|
||||||
stack = [(row, position)]
|
stack = [(row, position)]
|
||||||
|
help_row, help_position=row,position
|
||||||
while stack:
|
while stack:
|
||||||
help_row, help_position = stack.pop()
|
help_row, help_position = stack.pop()
|
||||||
if help_row == '\n':
|
if help_row == '':
|
||||||
if help_position in what_is_the_ended_positions():
|
help_row = '\n'
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
next_character_array = find_next_position(help_position, help_row[0])
|
next_character_array = find_next_position(help_position, help_row[0])
|
||||||
if next_character_array:
|
if next_character_array:
|
||||||
for element_in_next_position_array in next_character_array:
|
for element_in_next_position_array in next_character_array:
|
||||||
|
|
||||||
stack.append((help_row[1:], element_in_next_position_array))
|
stack.append((help_row[1:], element_in_next_position_array))
|
||||||
|
|
||||||
return False
|
# if help_row == '\n':
|
||||||
|
# if help_position in what_is_the_ended_positions():
|
||||||
|
# return True
|
||||||
|
# else:
|
||||||
|
# return False
|
||||||
|
if help_row == '\n':
|
||||||
|
if help_position in what_is_the_ended_positions():
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
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:
|
with open(used_table, 'r') as readed_used_table:
|
||||||
take_all_possible_positions = []
|
take_all_possible_positions = []
|
||||||
for row_used_table in readed_used_table:
|
for row_used_table in readed_used_table:
|
||||||
line = row_used_table.strip().split(' ')
|
line = row_used_table.strip().split('\t')
|
||||||
if len(line) != 1:
|
if len(line) != 1:
|
||||||
if position == line[0] and character == line[2]:
|
|
||||||
take_all_possible_positions.append(line[1])
|
|
||||||
|
|
||||||
|
if position == line[0] and character == line[2] or position == line[0] and line[2] == '<eps>':
|
||||||
|
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():
|
||||||
@ -44,14 +48,14 @@ def what_is_the_ended_positions():
|
|||||||
array += line
|
array += line
|
||||||
return array
|
return array
|
||||||
|
|
||||||
used_table = 'test.arg'
|
used_table = 'simple1.arg'
|
||||||
input_file = 'test.in'
|
input_file = 'simple1.in'
|
||||||
output_file = 'test.out'
|
output_file = 'simple1.out'
|
||||||
|
|
||||||
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:
|
||||||
if line_checking(row_input_file, '0'):
|
if line_checking(row_input_file, '0'):
|
||||||
write_answer('YES')
|
write_answer('TRUE', row_input_file)
|
||||||
else:
|
else:
|
||||||
write_answer('NO')
|
write_answer('FALSE', row_input_file)
|
||||||
|
8
TaskC04/simple1.out
Normal file
8
TaskC04/simple1.out
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FALSE a
|
||||||
|
FALSE ab
|
||||||
|
TRUE abc
|
||||||
|
FALSE abcd
|
||||||
|
FALSE aaaaab
|
||||||
|
TRUE abc
|
||||||
|
FALSE xyz
|
||||||
|
FALSE 0
|
9
TaskC04/simple2.out
Normal file
9
TaskC04/simple2.out
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
TRUE kot
|
||||||
|
TRUE ac
|
||||||
|
TRUE abc
|
||||||
|
TRUE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
|
||||||
|
FALSE abcd
|
||||||
|
FALSE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc
|
||||||
|
FALSE kotek
|
||||||
|
FALSE kotabc
|
||||||
|
TRUE kot
|
Loading…
Reference in New Issue
Block a user