Fixed C00-C03

This commit is contained in:
IgnBys 2023-11-19 17:38:19 +01:00
parent b3c8c2cab0
commit 2eed53581b
14 changed files with 199 additions and 230 deletions

View File

@ -1,3 +1,7 @@
NO NO
NO NO
YES YES
YES
NO
NO
NO

View File

@ -1,66 +0,0 @@
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')

View File

@ -1,37 +1,59 @@
import sys import sys
sys.setrecursionlimit(5000)
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')
def line_checking(row, position):
stack = [(row, position)]
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
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:
# array_which_contain_accepted_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('\t') line = row_used_table.strip().split('\t')
if len(line) != 1: if len(line) != 1:
if position == line[0] and character == line[2]: if position == line[0] and character == line[2]:
take_all_possible_positions.append(line[1])
return True,line[1] return take_all_possible_positions
used_table = 'testnfa.arg' def what_is_the_ended_positions():
input_file = 'testnfa.in' array = []
output_file = 'testnfa.out' with open(used_table, 'r') as file:
# used_table = sys.argv[1] for row in file:
# input_file = sys.argv[2] line = row.strip().split('\t')
# output_file = sys.argv[3] if len(line) == 1:
array += line
return array
# 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(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:
result = False if line_checking(row_input_file, '0'):
next_position = None write_answer('YES')
position = '0' else:
for character in row_input_file: write_answer('NO')
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

View File

@ -1,8 +1,8 @@
Yes YES
Yes YES
NO NO
NO NO
NO NO
Yes YES
NO NO
Yes YES

View File

@ -1,39 +1,28 @@
import sys import sys
sys.setrecursionlimit(5000) sys.setrecursionlimit(5000)
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')
# def remove_first_symbol_from_the_list():
def line_checking(row, position): def line_checking(row, position):
help_row = row stack = [(row, position)]
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
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
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:
@ -45,22 +34,26 @@ def find_next_position(position, character):
take_all_possible_positions.append(line[1]) 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: with open(used_table, 'r') as file:
for row in file: for row in file:
line = row.strip().split('\t') line = row.strip().split('\t')
if len(line)==1: if len(line) == 1:
array += line array += line
return array return array
used_table = 'test.arg'
input_file = 'test.in' # used_table = 'test.arg'
output_file = 'test.out' # input_file = 'test.in'
# what_is_the_ended_positions() # output_file = 'test.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(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')==True: if line_checking(row_input_file, '0'):
write_answer('YES') write_answer('YES')
else: else:
write_answer('NO') write_answer('NO')

View File

@ -1,14 +1,8 @@
0 0 a 0 0 a
0 0 b
0 0 c 0 0 c
0 1 b 0 1 b
1 2 a
1 2 b 1 2 b
1 3 a 1 2 c
1 3 c
2 3 a
2 3 c
2 2 b
3 0 a
3 0 c
3 1 b
3
2 2

View File

@ -1,39 +1,28 @@
import sys import sys
sys.setrecursionlimit(5000) sys.setrecursionlimit(5000)
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')
# def remove_first_symbol_from_the_list():
def line_checking(row, position): def line_checking(row, position):
help_row = row stack = [(row, position)]
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
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
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:
@ -45,22 +34,26 @@ def find_next_position(position, character):
take_all_possible_positions.append(line[1]) 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: with open(used_table, 'r') as file:
for row in file: for row in file:
line = row.strip().split('\t') line = row.strip().split('\t')
if len(line)==1: if len(line) == 1:
array += line array += line
return array return array
used_table = 'test.arg'
input_file = 'test.in' # used_table = 'test.arg'
output_file = 'test.out' # input_file = 'test.in'
# what_is_the_ended_positions() # output_file = 'test.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(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')==True: if line_checking(row_input_file, '0'):
write_answer('YES') write_answer('YES')
else: else:
write_answer('NO') write_answer('NO')

9
TaskC02/test.arg Normal file
View File

@ -0,0 +1,9 @@
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

6
TaskC02/test.out Normal file
View File

@ -0,0 +1,6 @@
YES
NO
YES
NO
YES
NO

View File

@ -1,39 +1,28 @@
import sys import sys
sys.setrecursionlimit(5000) sys.setrecursionlimit(5000)
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')
# def remove_first_symbol_from_the_list():
def line_checking(row, position): def line_checking(row, position):
help_row = row stack = [(row, position)]
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
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
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:
@ -45,22 +34,26 @@ def find_next_position(position, character):
take_all_possible_positions.append(line[1]) 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: with open(used_table, 'r') as file:
for row in file: for row in file:
line = row.strip().split('\t') line = row.strip().split('\t')
if len(line)==1: if len(line) == 1:
array += line array += line
return array return array
used_table = 'test.arg'
input_file = 'test.in' # used_table = 'test.arg'
output_file = 'test.out' # input_file = 'test.in'
# what_is_the_ended_positions() # output_file = 'test.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(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')==True: if line_checking(row_input_file, '0'):
write_answer('YES') write_answer('YES')
else: else:
write_answer('NO') write_answer('NO')

13
TaskC03/test.arg Normal file
View File

@ -0,0 +1,13 @@
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

7
TaskC03/test.out Normal file
View File

@ -0,0 +1,7 @@
YES
YES
YES
NO
NO
NO
NO

10
TaskC04/eps.out Normal file
View File

@ -0,0 +1,10 @@
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO

View File

@ -1,39 +1,28 @@
import sys import sys
sys.setrecursionlimit(5000) sys.setrecursionlimit(5000)
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')
# def remove_first_symbol_from_the_list():
def line_checking(row, position): def line_checking(row, position):
help_row = row stack = [(row, position)]
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
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
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:
@ -45,22 +34,24 @@ def find_next_position(position, character):
take_all_possible_positions.append(line[1]) 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: with open(used_table, 'r') as file:
for row in file: for row in file:
line = row.strip().split('\t') line = row.strip().split('\t')
if len(line)==1: if len(line) == 1:
array += line array += line
return array 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'
# what_is_the_ended_positions()
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')==True: if line_checking(row_input_file, '0'):
write_answer('YES') write_answer('YES')
else: else:
write_answer('NO') write_answer('NO')