TaskC00 ended with recursion problem
This commit is contained in:
parent
21b8220725
commit
56bcb5e4c5
@ -1,4 +1,4 @@
|
||||
сYES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
@ -1,3 +1,3 @@
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
|
3
TaskC00/long.out
Normal file
3
TaskC00/long.out
Normal file
@ -0,0 +1,3 @@
|
||||
NO
|
||||
NO
|
||||
YES
|
66
TaskC00/main.py
Normal file
66
TaskC00/main.py
Normal file
@ -0,0 +1,66 @@
|
||||
import sys
|
||||
sys.setrecursionlimit(5000)
|
||||
|
||||
def write_answer(answer):
|
||||
with open(output_file, 'a') as file:
|
||||
file.write(answer+'\n')
|
||||
|
||||
# def remove_first_symbol_from_the_list():
|
||||
|
||||
def line_checking(row, position):
|
||||
help_row = row
|
||||
help_position = position
|
||||
next_character_array =[]
|
||||
bool_value = False
|
||||
for element in row:
|
||||
if element=='\n':
|
||||
if position in what_is_the_ended_positions():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
next_character_array = find_next_position(help_position, element)
|
||||
if next_character_array != []:
|
||||
if len(next_character_array)>1:
|
||||
for element_in_next_character_array in next_character_array:
|
||||
if bool_value ==True:
|
||||
break
|
||||
else:
|
||||
bool_value =line_checking(help_row[1:], element_in_next_character_array)
|
||||
else:
|
||||
# remove_first_symbol_from_the_list()
|
||||
help_row = help_row[1:]
|
||||
bool_value = line_checking(help_row, next_character_array[0])
|
||||
else:
|
||||
break
|
||||
return bool_value
|
||||
|
||||
|
||||
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('\t')
|
||||
if len(line) != 1:
|
||||
if position == line[0] and character == line[2]:
|
||||
take_all_possible_positions.append(line[1])
|
||||
|
||||
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
|
||||
used_table = 'long.arg'
|
||||
input_file = 'long.in'
|
||||
output_file = 'long.out'
|
||||
# what_is_the_ended_positions()
|
||||
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:
|
||||
if line_checking(row_input_file, '0')==True:
|
||||
write_answer('YES')
|
||||
else:
|
||||
write_answer('NO')
|
37
TaskC00/run.py
Normal file
37
TaskC00/run.py
Normal file
@ -0,0 +1,37 @@
|
||||
import sys
|
||||
def write_answer(answer):
|
||||
with open(output_file, 'a') as file:
|
||||
file.write(answer+'\n')
|
||||
def find_next_position(position, character):
|
||||
with open(used_table, 'r') as readed_used_table:
|
||||
# array_which_contain_accepted_positions = []
|
||||
for row_used_table in readed_used_table:
|
||||
line = row_used_table.strip().split('\t')
|
||||
if len(line) != 1:
|
||||
if position == line[0] and character == line[2]:
|
||||
|
||||
return True,line[1]
|
||||
|
||||
used_table = 'testnfa.arg'
|
||||
input_file = 'testnfa.in'
|
||||
output_file = 'testnfa.out'
|
||||
# used_table = sys.argv[1]
|
||||
# input_file = sys.argv[2]
|
||||
# output_file = sys.argv[3]
|
||||
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:
|
||||
result = False
|
||||
next_position = None
|
||||
position = '0'
|
||||
for character in row_input_file:
|
||||
if character =='\n':
|
||||
if position=='3' or position =='4':
|
||||
write_answer('YES')
|
||||
break
|
||||
else:
|
||||
write_answer('NO')
|
||||
break
|
||||
result, next_position = find_next_position(position,character)
|
||||
if result == True:
|
||||
position = next_position
|
9
TaskC00/test1.out
Normal file
9
TaskC00/test1.out
Normal file
@ -0,0 +1,9 @@
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
8
TaskC00/testnfa.out
Normal file
8
TaskC00/testnfa.out
Normal file
@ -0,0 +1,8 @@
|
||||
Yes
|
||||
Yes
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
Yes
|
||||
NO
|
||||
Yes
|
Loading…
Reference in New Issue
Block a user