Compare commits
No commits in common. "59b85bff1887f9f1d8cdc46958b642476d99620a" and "213ae4ffda6983c929665fe6d6853a9fde9a5f6d" have entirely different histories.
59b85bff18
...
213ae4ffda
@ -1,11 +0,0 @@
|
|||||||
Read a description of a non-deterministic finite-state automaton in the AT&T format
|
|
||||||
(without weights) from the file in the first argument.
|
|
||||||
|
|
||||||
Read strings from the standard input.
|
|
||||||
If a string is accepted by the
|
|
||||||
automaton, write YES, otherwise- write NO.
|
|
||||||
|
|
||||||
The program is invoked like this: python run.py test1.arg test1.in test1.out
|
|
||||||
|
|
||||||
Note that not all transitions must be included in description.
|
|
||||||
If no transition is given for the given state and letter, write NO.
|
|
4041
TaskC00/long.arg
4041
TaskC00/long.arg
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
NO
|
|
||||||
NO
|
|
||||||
YES
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
@ -1,7 +0,0 @@
|
|||||||
aaa
|
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
aaaa
|
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
xyz
|
|
||||||
aba
|
|
||||||
a
|
|
@ -1,65 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
sys.setrecursionlimit(4500)
|
|
||||||
|
|
||||||
def AddTransition(transitions, state_from, state_to, symbol):
|
|
||||||
if state_from in transitions:
|
|
||||||
if symbol not in transitions[state_from]:
|
|
||||||
transitions[state_from][symbol] = {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from][symbol] |= {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from] = {symbol: {state_to}}
|
|
||||||
|
|
||||||
|
|
||||||
def AddFinalState(final_states, state):
|
|
||||||
final_states.add(state)
|
|
||||||
|
|
||||||
|
|
||||||
def GetFinalStates(transitions, final_states, string, current_state):
|
|
||||||
if not string:
|
|
||||||
return current_state if current_state in final_states else -1
|
|
||||||
|
|
||||||
symbol, rest = string[0], string[1:]
|
|
||||||
|
|
||||||
try:
|
|
||||||
for state in transitions[current_state][symbol]:
|
|
||||||
result = GetFinalStates(transitions, final_states, rest, state)
|
|
||||||
if result != -1:
|
|
||||||
return result
|
|
||||||
except KeyError:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return -1
|
|
||||||
|
|
||||||
|
|
||||||
def IsAccepted(transitions, final_states, string, initial_state):
|
|
||||||
final_state = GetFinalStates(transitions, final_states, string, initial_state)
|
|
||||||
return final_state in final_states
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
transitions = {}
|
|
||||||
final_states = set()
|
|
||||||
|
|
||||||
with open(sys.argv[1]) as table:
|
|
||||||
for line in table:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if len(line.split('\t')) == 3:
|
|
||||||
a, b, c = line.split('\t')
|
|
||||||
AddTransition(transitions, a, b, c)
|
|
||||||
else:
|
|
||||||
AddFinalState(final_states, line)
|
|
||||||
|
|
||||||
with open(sys.argv[2], 'r', encoding="utf-8") as input_data, open(sys.argv[3], 'w', encoding="utf-8") as output_data:
|
|
||||||
for line in input_data:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if IsAccepted(transitions, final_states, line, '0'):
|
|
||||||
output_data.write('YES\n')
|
|
||||||
else:
|
|
||||||
output_data.write('NO\n')
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
|||||||
0 1 x
|
|
||||||
0 4 y
|
|
||||||
0 4 z
|
|
||||||
1 4 x
|
|
||||||
1 2 y
|
|
||||||
1 4 z
|
|
||||||
2 4 x
|
|
||||||
2 3 z
|
|
||||||
2 4 y
|
|
||||||
3 4 x
|
|
||||||
3 4 y
|
|
||||||
3 4 z
|
|
||||||
4 4 x
|
|
||||||
4 4 y
|
|
||||||
4 4 z
|
|
||||||
3
|
|
@ -1,9 +0,0 @@
|
|||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
@ -1,9 +0,0 @@
|
|||||||
xxyz
|
|
||||||
xyz
|
|
||||||
xy
|
|
||||||
zz
|
|
||||||
xxy
|
|
||||||
yzx
|
|
||||||
|
|
||||||
x
|
|
||||||
xyzz
|
|
@ -1,9 +0,0 @@
|
|||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
@ -1,7 +0,0 @@
|
|||||||
0 1 a
|
|
||||||
1 0 a
|
|
||||||
1 2 b
|
|
||||||
1 3 b
|
|
||||||
2 4 c
|
|
||||||
3
|
|
||||||
4
|
|
@ -1,8 +0,0 @@
|
|||||||
YES
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
YES
|
|
@ -1,8 +0,0 @@
|
|||||||
abc
|
|
||||||
ab
|
|
||||||
abcd
|
|
||||||
aaaabc
|
|
||||||
aaaaaaaabc
|
|
||||||
aaaaaaabc
|
|
||||||
zzz
|
|
||||||
aaaaaaabc
|
|
@ -1,8 +0,0 @@
|
|||||||
YES
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
YES
|
|
@ -1,11 +0,0 @@
|
|||||||
Use a non deterministic finite-state automaton (FSA) engine from the TaskC00.
|
|
||||||
Create your own non deterministic FSA description to check whether the string second letter
|
|
||||||
from right is 'b'.
|
|
||||||
Don't use external files like in TaskF00 (description should be included in run file).
|
|
||||||
|
|
||||||
The alphabet is "a", "b", "C"
|
|
||||||
|
|
||||||
Read strings from the standard input.
|
|
||||||
If a string is accepted by the
|
|
||||||
automaton, write YES, otherwise- write NO.
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.setrecursionlimit(4500)
|
|
||||||
|
|
||||||
def AddTransition(transitions, state_from, state_to, symbol):
|
|
||||||
if state_from in transitions:
|
|
||||||
if symbol not in transitions[state_from]:
|
|
||||||
transitions[state_from][symbol] = {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from][symbol] |= {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from] = {symbol: {state_to}}
|
|
||||||
|
|
||||||
def AddFinalState(final_states, state):
|
|
||||||
final_states.add(state)
|
|
||||||
|
|
||||||
def GetFinalState(transitions, final_states, string, current_state):
|
|
||||||
if not string:
|
|
||||||
return current_state if current_state in final_states else -1
|
|
||||||
|
|
||||||
symbol, rest = string[0], string[1:]
|
|
||||||
|
|
||||||
try:
|
|
||||||
for state in transitions[current_state][symbol]:
|
|
||||||
result = GetFinalState(transitions, final_states, rest, state)
|
|
||||||
if result != -1:
|
|
||||||
return result
|
|
||||||
except KeyError:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def IsAccepted(transitions, finalStates, string, initial_state):
|
|
||||||
finalState = GetFinalState(transitions, finalStates, string, initial_state)
|
|
||||||
return finalState in finalStates
|
|
||||||
|
|
||||||
|
|
||||||
transitions = {}
|
|
||||||
finalStates = {2}
|
|
||||||
|
|
||||||
AddTransition(transitions, 0, 0, 'a')
|
|
||||||
AddTransition(transitions, 0, 0, 'b')
|
|
||||||
AddTransition(transitions, 0, 0, 'c')
|
|
||||||
AddTransition(transitions, 0, 1, 'b')
|
|
||||||
AddTransition(transitions, 1, 2, 'a')
|
|
||||||
AddTransition(transitions, 1, 2, 'b')
|
|
||||||
AddTransition(transitions, 1, 2, 'c')
|
|
||||||
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if IsAccepted(transitions, finalStates, line, 0):
|
|
||||||
print('YES')
|
|
||||||
else:
|
|
||||||
print('NO')
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
0 0 a
|
|
||||||
0 0 b
|
|
||||||
0 0 c
|
|
||||||
0 1 b
|
|
||||||
1 2 a
|
|
||||||
1 2 b
|
|
||||||
1 2 c
|
|
||||||
2
|
|
@ -1,6 +0,0 @@
|
|||||||
YES
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
YES
|
|
@ -1,6 +0,0 @@
|
|||||||
abc
|
|
||||||
abbc
|
|
||||||
bca
|
|
||||||
b
|
|
||||||
abaa
|
|
||||||
aaacbb
|
|
@ -1,11 +0,0 @@
|
|||||||
Use a non deterministic finite-state automaton (FSA) engine from the TaskC00.
|
|
||||||
Create your own non deterministic FSA description to check whether the string
|
|
||||||
ends with "ab"
|
|
||||||
Don't use external files like in TaskF00 (description should be included in run file).
|
|
||||||
|
|
||||||
The alphabet is "a", "b", "C"
|
|
||||||
|
|
||||||
Read strings from the standard input.
|
|
||||||
If a string is accepted by the
|
|
||||||
automaton, write YES, otherwise- write NO.
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.setrecursionlimit(4500)
|
|
||||||
|
|
||||||
def AddTransition(transitions, state_from, state_to, symbol):
|
|
||||||
if state_from in transitions:
|
|
||||||
if symbol not in transitions[state_from]:
|
|
||||||
transitions[state_from][symbol] = {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from][symbol] |= {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from] = {symbol: {state_to}}
|
|
||||||
|
|
||||||
def AddFinalState(final_states, state):
|
|
||||||
final_states.add(state)
|
|
||||||
|
|
||||||
def GetFinalState(transitions, final_states, string, current_state):
|
|
||||||
if not string:
|
|
||||||
return current_state if current_state in final_states else -1
|
|
||||||
|
|
||||||
symbol, rest = string[0], string[1:]
|
|
||||||
|
|
||||||
try:
|
|
||||||
for state in transitions[current_state][symbol]:
|
|
||||||
result = GetFinalState(transitions, final_states, rest, state)
|
|
||||||
if result != -1:
|
|
||||||
return result
|
|
||||||
except KeyError:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def IsAccepted(transitions, finalStates, string, initial_state):
|
|
||||||
finalState = GetFinalState(transitions, finalStates, string, initial_state)
|
|
||||||
return finalState in finalStates
|
|
||||||
|
|
||||||
|
|
||||||
transitions = {}
|
|
||||||
finalStates = {2}
|
|
||||||
|
|
||||||
AddTransition(transitions, 0, 0, 'a')
|
|
||||||
AddTransition(transitions, 0, 0, 'b')
|
|
||||||
AddTransition(transitions, 0, 0, 'c')
|
|
||||||
AddTransition(transitions, 0, 1, 'a')
|
|
||||||
AddTransition(transitions, 1, 2, 'b')
|
|
||||||
AddTransition(transitions, 2, 0, 'a')
|
|
||||||
AddTransition(transitions, 2, 0, 'b')
|
|
||||||
AddTransition(transitions, 2, 0, 'c')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if IsAccepted(transitions, finalStates, line, 0):
|
|
||||||
print('YES')
|
|
||||||
else:
|
|
||||||
print('NO')
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
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
|
|
@ -1,6 +0,0 @@
|
|||||||
YES
|
|
||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
YES
|
|
||||||
NO
|
|
@ -1,6 +0,0 @@
|
|||||||
ab
|
|
||||||
a
|
|
||||||
abbab
|
|
||||||
bbbbb
|
|
||||||
ababaab
|
|
||||||
b
|
|
@ -1,10 +0,0 @@
|
|||||||
Use a non deterministic finite-state automaton (FSA) engine from the TaskC00.
|
|
||||||
Create your own non deterministic FSA description to check whether the string
|
|
||||||
contains "abc"
|
|
||||||
Don't use external files like in TaskF00 (description should be included in run file).
|
|
||||||
|
|
||||||
The alphabet is "a", "b", "c"
|
|
||||||
|
|
||||||
Read strings from the standard input.
|
|
||||||
If a string is accepted by the
|
|
||||||
automaton, write YES, otherwise- write NO.
|
|
@ -1,63 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.setrecursionlimit(4500)
|
|
||||||
|
|
||||||
def AddTransition(transitions, state_from, state_to, symbol):
|
|
||||||
if state_from in transitions:
|
|
||||||
if symbol not in transitions[state_from]:
|
|
||||||
transitions[state_from][symbol] = {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from][symbol] |= {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from] = {symbol: {state_to}}
|
|
||||||
|
|
||||||
def AddFinalState(final_states, state):
|
|
||||||
final_states.add(state)
|
|
||||||
|
|
||||||
def GetFinalState(transitions, final_states, string, current_state):
|
|
||||||
if not string:
|
|
||||||
return current_state if current_state in final_states else -1
|
|
||||||
|
|
||||||
symbol, rest = string[0], string[1:]
|
|
||||||
|
|
||||||
try:
|
|
||||||
for state in transitions[current_state][symbol]:
|
|
||||||
result = GetFinalState(transitions, final_states, rest, state)
|
|
||||||
if result != -1:
|
|
||||||
return result
|
|
||||||
except KeyError:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def IsAccepted(transitions, finalStates, string, initial_state):
|
|
||||||
finalState = GetFinalState(transitions, finalStates, string, initial_state)
|
|
||||||
return finalState in finalStates
|
|
||||||
|
|
||||||
|
|
||||||
transitions = {}
|
|
||||||
finalStates = {3}
|
|
||||||
|
|
||||||
AddTransition(transitions, 0, 0, 'b')
|
|
||||||
AddTransition(transitions, 0, 0, 'c')
|
|
||||||
AddTransition(transitions, 0, 1, 'a')
|
|
||||||
AddTransition(transitions, 1, 1, 'a')
|
|
||||||
AddTransition(transitions, 1, 0, 'c')
|
|
||||||
AddTransition(transitions, 1, 2, 'b')
|
|
||||||
AddTransition(transitions, 2, 1, 'a')
|
|
||||||
AddTransition(transitions, 2, 0, 'b')
|
|
||||||
AddTransition(transitions, 2, 3, 'c')
|
|
||||||
AddTransition(transitions, 3, 3, 'a')
|
|
||||||
AddTransition(transitions, 3, 3, 'b')
|
|
||||||
AddTransition(transitions, 3, 3, 'c')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if IsAccepted(transitions, finalStates, line, 0):
|
|
||||||
print('YES')
|
|
||||||
else:
|
|
||||||
print('NO')
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
0 0 b
|
|
||||||
0 0 c
|
|
||||||
0 1 a
|
|
||||||
1 1 a
|
|
||||||
1 0 c
|
|
||||||
1 2 b
|
|
||||||
2 1 a
|
|
||||||
2 0 b
|
|
||||||
2 3 c
|
|
||||||
3 3 a
|
|
||||||
3 3 b
|
|
||||||
3 3 c
|
|
||||||
3
|
|
@ -1,7 +0,0 @@
|
|||||||
YES
|
|
||||||
YES
|
|
||||||
YES
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
||||||
NO
|
|
@ -1,7 +0,0 @@
|
|||||||
abc
|
|
||||||
acabc
|
|
||||||
acabccb
|
|
||||||
abbab
|
|
||||||
bbbbb
|
|
||||||
ababaab
|
|
||||||
bc
|
|
@ -1,22 +0,0 @@
|
|||||||
Deterministic automaton III
|
|
||||||
===========================
|
|
||||||
|
|
||||||
Read a description of a finite-state automaton in the AT&T format
|
|
||||||
(without weights) from the file in the first argument. Then, read strings from the
|
|
||||||
standard input. If a string is
|
|
||||||
accepted by the automated, write YES, a space and the string on the
|
|
||||||
standard output, otherwise — write NO, a space and the string.
|
|
||||||
|
|
||||||
If there is a non-determinism in the automaton, the first transition should be chosen.
|
|
||||||
|
|
||||||
The automaton can contain epsilon transitions ("<eps>" instead of a
|
|
||||||
character). They should be interpreted as follows: an epsilon
|
|
||||||
transition can be used (without "eating" a character from the input),
|
|
||||||
if there is no other transition applicable. You can assume that there
|
|
||||||
is at most one epsilon transition from a given state and that there
|
|
||||||
are no cycles with epsilon transition.
|
|
||||||
|
|
||||||
Your program does not have to check whether the description is correct
|
|
||||||
and whether the automaton is deterministic. You can assume that the
|
|
||||||
automaton does not contain epsilon transitions.
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
0 1 a
|
|
||||||
1 0 a
|
|
||||||
1 2 b
|
|
||||||
2 4 c
|
|
||||||
1 3 <eps>
|
|
||||||
3 4 d
|
|
||||||
3
|
|
||||||
4
|
|
@ -1,10 +0,0 @@
|
|||||||
TRUE a
|
|
||||||
FALSE aa
|
|
||||||
TRUE aaa
|
|
||||||
TRUE abc
|
|
||||||
TRUE aaabc
|
|
||||||
FALSE aaabcd
|
|
||||||
FALSE aabc
|
|
||||||
FALSE abd
|
|
||||||
TRUE ad
|
|
||||||
FALSE aad
|
|
@ -1,10 +0,0 @@
|
|||||||
a
|
|
||||||
aa
|
|
||||||
aaa
|
|
||||||
abc
|
|
||||||
aaabc
|
|
||||||
aaabcd
|
|
||||||
aabc
|
|
||||||
abd
|
|
||||||
ad
|
|
||||||
aad
|
|
4040
TaskC04/long.arg
4040
TaskC04/long.arg
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
FALSE aaa
|
|
||||||
FALSE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
TRUE aaaa
|
|
||||||
TRUE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
xyz
|
|
||||||
aba
|
|
||||||
a
|
|
@ -1,75 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
def ReadDescription(file_path):
|
|
||||||
nfa = {}
|
|
||||||
accepting_states = set()
|
|
||||||
|
|
||||||
with open(file_path, 'r', encoding="utf-8") as description:
|
|
||||||
for line in description:
|
|
||||||
split_data = line.strip().split('\t')
|
|
||||||
|
|
||||||
if len(split_data) == 3:
|
|
||||||
state, next_state, symbol = split_data
|
|
||||||
key = (int(state), symbol)
|
|
||||||
if key in nfa:
|
|
||||||
nfa[key].add(int(next_state))
|
|
||||||
else:
|
|
||||||
nfa[key] = {int(next_state)}
|
|
||||||
|
|
||||||
elif len(split_data) == 2:
|
|
||||||
state, next_state = split_data
|
|
||||||
key = (int(state), '<eps>')
|
|
||||||
if key in nfa:
|
|
||||||
nfa[key].add(int(next_state))
|
|
||||||
else:
|
|
||||||
nfa[key] = {int(next_state)}
|
|
||||||
|
|
||||||
elif len(split_data) == 1:
|
|
||||||
accepting_states.add(int(split_data[0]))
|
|
||||||
|
|
||||||
return nfa, accepting_states
|
|
||||||
|
|
||||||
def Epsilon(nfa, states):
|
|
||||||
epsilon = set(states)
|
|
||||||
stack = list(states)
|
|
||||||
|
|
||||||
while stack:
|
|
||||||
currentState = stack.pop()
|
|
||||||
epsilon_key = (currentState, '<eps>')
|
|
||||||
if epsilon_key in nfa:
|
|
||||||
epsTransitions = nfa[epsilon_key]
|
|
||||||
for nextState in epsTransitions:
|
|
||||||
if nextState not in epsilon:
|
|
||||||
epsilon.add(nextState)
|
|
||||||
stack.append(nextState)
|
|
||||||
|
|
||||||
return epsilon
|
|
||||||
|
|
||||||
def IsAccepted(nfa, inputString, current_states, accepting_states):
|
|
||||||
for symbol in inputString:
|
|
||||||
new_states = set()
|
|
||||||
|
|
||||||
for state in current_states:
|
|
||||||
key = (state, symbol)
|
|
||||||
if key in nfa:
|
|
||||||
new_states.update(nfa[key])
|
|
||||||
|
|
||||||
current_states = Epsilon(nfa, new_states)
|
|
||||||
|
|
||||||
return any(state in accepting_states for state in current_states)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
nfa_file = sys.argv[1]
|
|
||||||
nfa, acceptingStates = ReadDescription(nfa_file)
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
inputString = line.strip()
|
|
||||||
if inputString =='\n':
|
|
||||||
break
|
|
||||||
start_states = Epsilon(nfa, {0})
|
|
||||||
|
|
||||||
if IsAccepted(nfa, inputString, start_states, acceptingStates):
|
|
||||||
print("TRUE", inputString)
|
|
||||||
else:
|
|
||||||
print("FALSE", inputString)
|
|
@ -1,4 +0,0 @@
|
|||||||
0 1 a
|
|
||||||
1 2 b
|
|
||||||
2 3 c
|
|
||||||
3
|
|
@ -1,8 +0,0 @@
|
|||||||
FALSE a
|
|
||||||
FALSE ab
|
|
||||||
TRUE abc
|
|
||||||
FALSE abcd
|
|
||||||
FALSE aaaaab
|
|
||||||
TRUE abc
|
|
||||||
FALSE xyz
|
|
||||||
FALSE 0
|
|
@ -1,8 +0,0 @@
|
|||||||
a
|
|
||||||
ab
|
|
||||||
abc
|
|
||||||
abcd
|
|
||||||
aaaaab
|
|
||||||
abc
|
|
||||||
xyz
|
|
||||||
0
|
|
@ -1,9 +0,0 @@
|
|||||||
# automat akceptujący napis "ab*c" (b powielony dowolną liczbę razy) i "kot"
|
|
||||||
0 1 a
|
|
||||||
1 1 b
|
|
||||||
1 2 c
|
|
||||||
0 3 k
|
|
||||||
3 4 o
|
|
||||||
4 5 t
|
|
||||||
2
|
|
||||||
5
|
|
@ -1,9 +0,0 @@
|
|||||||
TRUE kot
|
|
||||||
TRUE ac
|
|
||||||
TRUE abc
|
|
||||||
TRUE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
|
|
||||||
FALSE abcd
|
|
||||||
FALSE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc
|
|
||||||
FALSE kotek
|
|
||||||
FALSE kotabc
|
|
||||||
TRUE kot
|
|
@ -1,9 +0,0 @@
|
|||||||
kot
|
|
||||||
ac
|
|
||||||
abc
|
|
||||||
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
|
|
||||||
abcd
|
|
||||||
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc
|
|
||||||
kotek
|
|
||||||
kotabc
|
|
||||||
kot
|
|
@ -1,49 +0,0 @@
|
|||||||
Dictionary
|
|
||||||
==========
|
|
||||||
|
|
||||||
Your program should read a finite-state automaton from file in the first argument.
|
|
||||||
The automaton is deterministic, you can assume it does not contain
|
|
||||||
cycles.
|
|
||||||
|
|
||||||
Each automaton path is labeled with a symbol sequence of the following form:
|
|
||||||
|
|
||||||
<input word>;<description>
|
|
||||||
|
|
||||||
e.g.:
|
|
||||||
|
|
||||||
biały;ADJ
|
|
||||||
dom;N
|
|
||||||
piła;N
|
|
||||||
piła;V
|
|
||||||
stali;N
|
|
||||||
stali;V
|
|
||||||
stali;ADJ
|
|
||||||
|
|
||||||
Next you should read words from the standard input.
|
|
||||||
For each word, you should all automaton
|
|
||||||
paths that begin a given word, the following symbol is ';'
|
|
||||||
(semicolon), e.g. for the word 'dom' we are looking for paths
|
|
||||||
beginning with 'dom;'. If there is no such path, the following message
|
|
||||||
should be printed:
|
|
||||||
|
|
||||||
<input word>;OOV
|
|
||||||
|
|
||||||
For instance, for the automaton given above and the input:
|
|
||||||
|
|
||||||
budynek
|
|
||||||
dom
|
|
||||||
piła
|
|
||||||
|
|
||||||
we should get:
|
|
||||||
|
|
||||||
budynek;OOV
|
|
||||||
dom;N
|
|
||||||
piła;N
|
|
||||||
piła;V
|
|
||||||
|
|
||||||
If there is more than one path for a given word, they should be given in alphabetical order.
|
|
||||||
|
|
||||||
The program does not have to check whether the automaton is correct
|
|
||||||
and whether it is deterministic and does not contain cycles.
|
|
||||||
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
0 1 b
|
|
||||||
0 2 d
|
|
||||||
0 3 p
|
|
||||||
0 4 s
|
|
||||||
1 5 i
|
|
||||||
2 6 o
|
|
||||||
3 7 i
|
|
||||||
4 8 t
|
|
||||||
5 9 a
|
|
||||||
6 10 m
|
|
||||||
7 11 ł
|
|
||||||
8 12 a
|
|
||||||
9 13 ł
|
|
||||||
10 14 ;
|
|
||||||
11 15 a
|
|
||||||
12 16 l
|
|
||||||
13 17 y
|
|
||||||
14 24 N
|
|
||||||
15 18 ;
|
|
||||||
16 19 i
|
|
||||||
17 20 ;
|
|
||||||
18 24 N
|
|
||||||
18 24 V
|
|
||||||
19 21 ;
|
|
||||||
20 22 A
|
|
||||||
21 22 A
|
|
||||||
21 24 N
|
|
||||||
21 24 V
|
|
||||||
22 23 D
|
|
||||||
23 24 J
|
|
||||||
24
|
|
@ -1 +0,0 @@
|
|||||||
dom;N
|
|
@ -1 +0,0 @@
|
|||||||
dom
|
|
15125
TaskC05/medium.arg
15125
TaskC05/medium.arg
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
arbuz;N
|
|
||||||
arbuza;N
|
|
||||||
arbuzowi;ADJ
|
|
||||||
arbuzowi;N
|
|
||||||
azylant;N
|
|
||||||
azylanci;N
|
|
||||||
azylantowie;OOV
|
|
@ -1,6 +0,0 @@
|
|||||||
arbuz
|
|
||||||
arbuza
|
|
||||||
arbuzowi
|
|
||||||
azylant
|
|
||||||
azylanci
|
|
||||||
azylantowie
|
|
@ -1,31 +0,0 @@
|
|||||||
0 1 b
|
|
||||||
0 2 d
|
|
||||||
0 3 p
|
|
||||||
0 4 s
|
|
||||||
1 5 i
|
|
||||||
2 6 o
|
|
||||||
3 7 i
|
|
||||||
4 8 t
|
|
||||||
5 9 a
|
|
||||||
6 10 m
|
|
||||||
7 11 ł
|
|
||||||
8 12 a
|
|
||||||
9 13 ł
|
|
||||||
10 14 ;
|
|
||||||
11 15 a
|
|
||||||
12 16 l
|
|
||||||
13 17 y
|
|
||||||
14 24 N
|
|
||||||
15 18 ;
|
|
||||||
16 19 i
|
|
||||||
17 20 ;
|
|
||||||
18 24 N
|
|
||||||
18 24 V
|
|
||||||
19 21 ;
|
|
||||||
20 22 A
|
|
||||||
21 22 A
|
|
||||||
21 24 N
|
|
||||||
21 24 V
|
|
||||||
22 23 D
|
|
||||||
23 24 J
|
|
||||||
24
|
|
@ -1,2 +0,0 @@
|
|||||||
piła;N
|
|
||||||
piła;V
|
|
@ -1 +0,0 @@
|
|||||||
piła
|
|
@ -1,31 +0,0 @@
|
|||||||
0 1 b
|
|
||||||
0 2 d
|
|
||||||
0 3 p
|
|
||||||
0 4 s
|
|
||||||
1 5 i
|
|
||||||
2 6 o
|
|
||||||
3 7 i
|
|
||||||
4 8 t
|
|
||||||
5 9 a
|
|
||||||
6 10 m
|
|
||||||
7 11 ł
|
|
||||||
8 12 a
|
|
||||||
9 13 ł
|
|
||||||
10 14 ;
|
|
||||||
11 15 a
|
|
||||||
12 16 l
|
|
||||||
13 17 y
|
|
||||||
14 24 N
|
|
||||||
15 18 ;
|
|
||||||
16 19 i
|
|
||||||
17 20 ;
|
|
||||||
18 24 N
|
|
||||||
18 24 V
|
|
||||||
19 21 ;
|
|
||||||
20 22 A
|
|
||||||
21 22 A
|
|
||||||
21 24 N
|
|
||||||
21 24 V
|
|
||||||
22 23 D
|
|
||||||
23 24 J
|
|
||||||
24
|
|
@ -1 +0,0 @@
|
|||||||
budynek;OOV
|
|
@ -1 +0,0 @@
|
|||||||
budynek
|
|
@ -1,75 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.setrecursionlimit(4500)
|
|
||||||
|
|
||||||
def AddTransition(transitions, state_from, state_to, symbol):
|
|
||||||
if state_from in transitions:
|
|
||||||
if symbol not in transitions[state_from]:
|
|
||||||
transitions[state_from][symbol] = {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from][symbol] |= {state_to}
|
|
||||||
else:
|
|
||||||
transitions[state_from] = {symbol: {state_to}}
|
|
||||||
|
|
||||||
def AddFinalState(final_states, state):
|
|
||||||
final_states.add(state)
|
|
||||||
|
|
||||||
def GetFinalStates(transitions, final_states, string, current_state):
|
|
||||||
if not string:
|
|
||||||
return current_state if current_state in final_states else -1
|
|
||||||
|
|
||||||
symbol, rest = string[0], string[1:]
|
|
||||||
|
|
||||||
if current_state in transitions and symbol in transitions[current_state]:
|
|
||||||
for state in transitions[current_state][symbol]:
|
|
||||||
result = GetFinalStates(transitions, final_states, rest, state)
|
|
||||||
if result != -1:
|
|
||||||
return result
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def IsAccepted(transitions, final_states, string, initial_state):
|
|
||||||
final_state = GetFinalStates(transitions, final_states, string, initial_state)
|
|
||||||
return final_state in final_states
|
|
||||||
|
|
||||||
|
|
||||||
def ChangeInput(transitions, final_states, string, initial_state):
|
|
||||||
possible_ending_parts = [';N', ';V', ';ADJ']
|
|
||||||
valid_results = []
|
|
||||||
|
|
||||||
for part in possible_ending_parts:
|
|
||||||
copy_string = string + part
|
|
||||||
if IsAccepted(transitions, final_states, copy_string, initial_state):
|
|
||||||
valid_results.append(copy_string)
|
|
||||||
|
|
||||||
if not valid_results:
|
|
||||||
valid_results.append(string + ';OOV')
|
|
||||||
|
|
||||||
return valid_results
|
|
||||||
|
|
||||||
|
|
||||||
transitions = {}
|
|
||||||
final_states = set()
|
|
||||||
|
|
||||||
fsaDescr = sys.argv[1] # 'elem.arg'
|
|
||||||
inputFile = sys.argv[2] # 'elem.in'
|
|
||||||
outputFile = sys.argv[3] # 'elem.out'
|
|
||||||
|
|
||||||
with open(fsaDescr, 'r', encoding="utf-8") as description:
|
|
||||||
for line in description:
|
|
||||||
line = line.rstrip()
|
|
||||||
|
|
||||||
if len(line.split('\t')) == 3:
|
|
||||||
a, b, c = line.split('\t')
|
|
||||||
AddTransition(transitions, a, b, c)
|
|
||||||
else:
|
|
||||||
AddFinalState(final_states, line)
|
|
||||||
|
|
||||||
with open(inputFile, 'r', encoding="utf-8") as inFile, open(outputFile, 'w', encoding="utf-8") as outFile:
|
|
||||||
for line in inFile:
|
|
||||||
line = line.rstrip()
|
|
||||||
results = ChangeInput(transitions, final_states, line, '0')
|
|
||||||
results.sort()
|
|
||||||
for result in results:
|
|
||||||
outFile.write(result + '\n')
|
|
||||||
# print(result)
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
Paths
|
|
||||||
======
|
|
||||||
|
|
||||||
Your program should read a finite-state automaton from
|
|
||||||
the standard input.
|
|
||||||
The automaton is deterministic, you can assume it does not contain
|
|
||||||
cycles. The automaton alphabet is the set of Polish lower-case letters
|
|
||||||
(English letters plus: ą, ć, ę, ł, ń, ó, ś, ź and ż).
|
|
||||||
|
|
||||||
Your program should print, on standard output, all the paths of the
|
|
||||||
automaton in alphabetical order (to be precise: order induced by byte
|
|
||||||
codes of strings, not according to the standard Polish order). "Print
|
|
||||||
a path" means print a text line containing all subsequent characters.
|
|
||||||
|
|
||||||
The program does not have to check whether the automaton is correct
|
|
||||||
and whether it is deterministic and does not contain cycles.
|
|
||||||
|
|
||||||
Weights (if any) should be disregarded.
|
|
||||||
|
|
||||||
NOTE 1. You can add `LANG=C sort` to your Bash wrapper for the write sort.
|
|
||||||
|
|
50648
TaskC06/medium.exp
50648
TaskC06/medium.exp
File diff suppressed because it is too large
Load Diff
14774
TaskC06/medium.in
14774
TaskC06/medium.in
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
a
|
|
13989
TaskC06/medium2.in
13989
TaskC06/medium2.in
File diff suppressed because it is too large
Load Diff
@ -1,47 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def read_fsa_description(file_path):
|
|
||||||
transitions = {}
|
|
||||||
final_states = set()
|
|
||||||
|
|
||||||
with open(file_path, 'r', encoding='utf-8') as file:
|
|
||||||
for line in file:
|
|
||||||
line = line.rstrip()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
|
|
||||||
parts = line.split('\t')
|
|
||||||
if len(parts) == 3:
|
|
||||||
state_from, state_to, symbol = parts[0], parts[1], parts[2]
|
|
||||||
if state_from in transitions:
|
|
||||||
transitions[state_from].append((state_to, symbol))
|
|
||||||
else:
|
|
||||||
transitions[state_from] = [(state_to, symbol)]
|
|
||||||
|
|
||||||
if len(parts)==1:
|
|
||||||
line = line.rstrip()
|
|
||||||
final_states.add(line)
|
|
||||||
|
|
||||||
return transitions, final_states
|
|
||||||
|
|
||||||
def generate_paths(transitions, current_state, current_path, final_states):
|
|
||||||
paths = []
|
|
||||||
if current_state in final_states:
|
|
||||||
paths.append("".join(current_path))
|
|
||||||
|
|
||||||
if current_state in transitions:
|
|
||||||
for next_state, symbol in transitions[current_state]:
|
|
||||||
paths.extend(generate_paths(transitions, next_state, current_path + [symbol], final_states))
|
|
||||||
|
|
||||||
return paths
|
|
||||||
|
|
||||||
|
|
||||||
fsa_description_file = sys.argv[1]#'medium.in'
|
|
||||||
transitions, final_states = read_fsa_description(fsa_description_file)
|
|
||||||
paths = generate_paths(transitions, '0', [], final_states)
|
|
||||||
|
|
||||||
for path in sorted(paths):
|
|
||||||
print(path)
|
|
||||||
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
|||||||
biały
|
|
||||||
dom
|
|
||||||
piła
|
|
||||||
stali
|
|
@ -1,18 +0,0 @@
|
|||||||
0 1 b
|
|
||||||
0 2 d
|
|
||||||
0 3 p
|
|
||||||
0 4 s
|
|
||||||
1 5 i
|
|
||||||
2 6 o
|
|
||||||
3 7 i
|
|
||||||
4 8 t
|
|
||||||
5 9 a
|
|
||||||
6 14 m
|
|
||||||
7 10 ł
|
|
||||||
8 11 a
|
|
||||||
9 12 ł
|
|
||||||
10 14 a
|
|
||||||
11 13 l
|
|
||||||
12 14 y
|
|
||||||
13 14 i
|
|
||||||
14
|
|
@ -1,3 +0,0 @@
|
|||||||
biały
|
|
||||||
piła
|
|
||||||
stali
|
|
@ -1,18 +0,0 @@
|
|||||||
0 1 b
|
|
||||||
0 2 d
|
|
||||||
0 3 p
|
|
||||||
0 4 s
|
|
||||||
1 5 i
|
|
||||||
2 6 o
|
|
||||||
3 7 i
|
|
||||||
4 8 t
|
|
||||||
5 9 a
|
|
||||||
6 15 m
|
|
||||||
7 10 ł
|
|
||||||
8 11 a
|
|
||||||
9 12 ł
|
|
||||||
10 14 a
|
|
||||||
11 13 l
|
|
||||||
12 14 y
|
|
||||||
13 14 i
|
|
||||||
14
|
|
Loading…
Reference in New Issue
Block a user