Compare commits

..

No commits in common. "master" and "5c739e9cf709c3489b0ba32eef50f055277e08b7" have entirely different histories.

419 changed files with 458 additions and 1495861 deletions

View File

@ -1,122 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="72cf1fbd-40b3-47aa-ad24-b4e28ca48019" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/jezykiformalne.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2XTqxj3Jb6nsJrXb6dR6Eezc5p6" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "J:/PycharmProjects/JezykiFormalne",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager" selected="Python.main">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jezykiformalne" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/TaskC00" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/TaskC00/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="run" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jezykiformalne" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/TaskB00" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/TaskB00/run.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.main" />
<item itemvalue="Python.run" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="72cf1fbd-40b3-47aa-ad24-b4e28ca48019" name="Changes" comment="" />
<created>1698663666324</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1698663666324</updated>
<workItem from="1698663667983" duration="3669000" />
<workItem from="1698667393874" duration="591000" />
<workItem from="1698875504210" duration="801000" />
<workItem from="1698876438874" duration="278000" />
<workItem from="1700049092114" duration="71000" />
<workItem from="1700049195784" duration="1534000" />
<workItem from="1701083054912" duration="676000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/jezykiformalne$main.coverage" NAME="main Coverage Results" MODIFIED="1700050514289" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/TaskC00" />
<SUITE FILE_PATH="coverage/jezykiformalne$run.coverage" NAME="run Coverage Results" MODIFIED="1698667882969" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/TaskB00" />
</component>
</project>

349
README.md
View File

@ -1,11 +1,6 @@
## Zajęcia 1
Copyright AMU Poznan
Made by multiple people
### Informacje na temat przedmiotu
Prowadzący: Jacek Kałużny
@ -23,3 +18,347 @@ W ten sposób będziemy aktualizować zadania co zajęcia.
Zadania robimy do końca soboty poprzedzającej zajęcia
Rozwiązanie zapisujemy w pliku run.py
## Zajęcia 2 Wyrażenia regularne
Dokumentacja wyrażeń regularnych w python3: https://docs.python.org/3/library/re.html
### Podstawowe funkcje
search - zwraca pierwsze dopasowanie w napisie
findall - zwraca listę wszystkich dopasowań (nienakładających się na siebie)
match - zwraca dopasowanie od początku string
To tylko podstawowe funkcje, z których będziemy korzystać. W dokumentacji opisane są wszystkie.
### Obiekt match
```
import re
answer = re.search('na','banan')
print(answer)
print(answer.start())
print(answer.end())
print(answer.group())
answer = re.search('na','kabanos')
print(answer)
type(answer)
if answer:
print(answer.group())
else:
pass
```
### Metaznaki
- [] - zbiór znaków
- . - jakikolwiek znak
- ^ - początek napisu
- $ - koniec napisu
- ? - znak występuje lub nie występuje
- \* - zero albo więcej pojawień się
- \+ - jeden albo więcej pojawień się
- {} - dokładnie tyle pojawień się
- | - lub
- () - grupa
- \ -znak ucieczki
- \d digit
- \D nie digit
- \s whitespace
- \S niewhitespace
### Flagi
Można użyć specjalnych flag, np:
`re.search('ma', 'AlA Ma KoTa', re.IGNORECASE)`.
### Przykłady (objaśnienia na laboratoriach)
Do nauki lepiej użyć pythona w wersji interaktywnej, a najlepiej ipython.
```
import re
text = 'Ala ma kota i hamak, oraz 150 bananów.'
re.search('ma',text)
re.match('ma',text)
re.match('Ala ma',text)
re.findall('ma',text)
re.findall('[mn]a',text)
re.findall('[0-9]',text)
re.findall('[0-9abc]',text)
re.findall('[a-z][a-z]ma[a-z]',text)
re.findall('[a-zA-Z][a-zA-Z]ma[a-zA-z0-9]',text)
re.findall('\d',text)
re.search('[0-9][0-9][0-9]',text)
re.search('[\d][\d][\d]',text)
re.search('\d{2}',text)
re.search('\d{3}',text)
re.search('\d+',text)
re.search('\d+ bananów',text)
re.search('\d* bananów','Ala ma dużo bananów')
re.search('\d* bananów',text)
re.search('ma \d? bananów','Ala ma 5 bananów')
re.search('ma ?\d? bananów','Ala ma bananów')
re.search('ma( \d)? bananów','Ala ma bananów')
re.search('\d+ bananów','Ala ma 10 bananów albo 20 bananów')
re.search('\d+ bananów$','Ala ma 10 bananów albo 20 bananów')
text = 'Ala ma kota i hamak, oraz 150 bananów.'
re.search('\d+ bananów',text)
re.search('\d+\sbananów',text)
re.search('kota . hamak',text)
re.search('kota . hamak','Ala ma kota z hamakiem')
re.search('kota .* hamak','Ala ma kota lub hamak')
re.search('\.',text)
re.search('kota|psa','Ala ma kota lub hamak')
re.findall('kota|psa','Ala ma kota lub psa')
re.search('kota (i|lub) psa','Ala ma kota lub psa')
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(0)
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(1)
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(2)
```
### Przykłady wyrażenia regularne 2 (objaśnienia na laboratoriach)
#### ^
```
re.search('[0-9]+', '123-456-789')
re.search('[^0-9][0-9]+[^0-9]', '123-456-789')
```
#### cudzysłów
'' oraz "" - oznaczają to samo w pythonie
' ala ma psa o imieniu "Burek"'
" ala ma psa o imieniu 'Burek' "
' ala ma psa o imieniu \'Burek\' '
" ala ma psa o imieniu \"Burek\" "
#### multiline string
#### raw string
przy raw string znaki \ traktowane są jako zwykłe znaki \
chociaż nawet w raw string nadal są escapowane (ale wtedy \ pozostają również w stringu bez zmian)
https://docs.python.org/3/reference/lexical_analysis.html
dobra praktyka - wszędzie escapować
```
'\\'
print('\\')
r'\\'
print(r'\\')
print("abcd")
print("ab\cd")
print(r"ab\cd")
print("ab\nd")
print(r"ab\nd")
print("\"")
print(r"\"")
print("\")
print(r"\")
re.search('\\', r'a\bc')
re.search(r'\\', r'a\bc')
re.search('\\\\', r'a\bc')
```
#### RE SUB
```
re.sub(pattern, replacement, string)
re.sub('a','b', 'ala ma kota')
```
#### backreferencje:
```
re.search(r' \d+ \d+', 'ala ma 41 41 kota')
re.search(r' \d+ \d+', 'ala ma 41 123 kota')
re.search(r' (\d+) \1', 'ala ma 41 41 kota')
re.search(r' (\d+) \1', 'ala ma 41 123 kota')
```
#### lookahead ( to sa takie assercje):
```
re.search(r'ma kot', 'ala ma kot')
re.search(r'ma kot(?=[ay])', 'ala ma kot')
re.search(r'ma kot(?=[ay])', 'ala ma kotka')
re.search(r'ma kot(?=[ay])', 'ala ma koty')
re.search(r'ma kot(?=[ay])', 'ala ma kota')
re.search(r'ma kot(?![ay])', 'ala ma kot')
re.search(r'ma kot(?![ay])', 'ala ma kotka')
re.search(r'ma kot(?![ay])', 'ala ma koty')
re.search(r'ma kot(?![ay])', 'ala ma kota')
```
#### named groups
```
r = re.search(r'ma (?P<ilepsow>\d+) kotow i (?P<ilekotow>\d+) psow', 'ala ma 100 kotow i 200 psow')
r.groups()
r.groups('ilepsow')
r.groups('ilekotow')
```
#### re.split
```
('a,b.c,d').split(',')
('a,b.c,d').split(',')
('a,b.c,d').split(',.')
re.split(r',', 'a,b.c,d')
re.split(r'[.,]', 'a,b.c,d')
```
#### \w word character
```
\w - matchuje Unicod word character , jeżeli flaga ASCII to [a-zA-Z0-9_]
\w - odwrotne do \W, jezeli flaga ASCI to [^a-zA-Z0-9_]
re.findall(r'\w+', 'ala ma 3 koty.')
re.findall(r'\W+', 'ala ma 3 koty.')
```
#### początek albo koniec słowa | word boundary
```
re.search(r'\bkot\b', 'Ala ma kota')
re.search(r'\bkot\b', 'Ala ma kot')
re.search(r'\bkot\b', 'Ala ma kot.')
re.search(r'\bkot\b', 'Ala ma kot ')
re.search(r'\Bot\B', 'Ala ma kot ')
re.search(r'\Bot\B', 'Ala ma kota ')
```
#### MULTILINE
```
re.findall(r'^Ma', 'Ma kota Ala\nMa psa Jacek')
re.findall(r'^Ma', 'Ma kota Ala\nMa psa Jacek', re.MULTILINE)
```
#### RE.COMPILE
## zajęcia 6
instalacja https://pypi.org/project/google-re2/
### DFA i NDFA
```
import re2 as re
n = 50
regexp = "a?"*n+"a"*n
s = "a"*n
re.match(regexp, s)
```
```
re.match(r"(\d)abc\1", "3abc3") # re2 nie obsługuje backreferencji
```
re2 max memory - podniesienie limitu
time # mierzenie czasu działania
gdyby ktoś chciał poczytać więcej:
https://swtch.com/~rsc/regexp/regexp1.html
### UTF-8
```
c = ""
ord(c)
chr(8459)
8* 16**2 + 0 * 16**(1) + 0*16**(0)
15*16**3 + 15* 16**2 + 15 * 16**(1) + 15*16**(0)
```
```
xxd -b file
xxd file
```
termin oddawania zadań - 15. listopada
## Zajęcia 7
https://www.openfst.org/twiki/bin/view/GRM/Thrax
https://www.cs.jhu.edu/~jason/465/hw-ofst/hw-ofst.pdf
Wszystkie zadania proszę robić na wzór `TaskH00`. Proszę umieszczać gramatykę w pliku `grammar.grm` oraz
opisywać finalną regułę nazwą `FinalRule`.
## KOLOKWIUM
Operatory, obowiązujące na kolokwium
====================================
* kwantyfikatory `-` `*` `+` `?` `{n}` `{n,}` `{n, m}`
* alternatywa — `|`
* klasy znaków — `[...]`
* zanegowane klasy znaków — `[^...]`
* dowolny znak — `.`
* unieważnianie znaków specjalnych — \
* operatory zakotwiczające — `^` `$`
Na kolokwium do każdego z 4 pytań będą 3 podpunkty. Na każdy podpunkt odpowiadamy TAK/NIE. Czas trwania to 15 minut.
- zawsze daszek i dolar
- nie bierzemy pod uwagę capturing (jeżeli są pytania o równoważne)
- proponuję wydrukować cały test w wersji bez opdowiedzi i sprawdzać
Do zaliczenia należy zdobyć conajmniej 10 punktów.

44
TaskA01/TaskAO1.py Normal file
View File

@ -0,0 +1,44 @@
import re
def openFile(fileName,hamletArray = ['H','a', 'm', 'l', 'e', 't'], hamletFullWord = r'Hamlet'):
with open(fileName, "r", encoding="utf-8") as file:
file_contents = file.read()
repCounter = 0
line = ''
counter = 0
checkWord = ''
index = 0
length = len(file_contents)
while index < length:
character = file_contents[index]
line += character
if len(checkWord) < len(hamletFullWord):
if re.match(hamletArray[counter], character):
checkWord+=character
counter += 1
else:
checkWord = ''
counter = 0
if character=='\n':
if checkWord=='Hamlet':
print(line)
line = ''
counter = 0
checkWord = ''
index+=1
#
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('shakespeare.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('shakespeare.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

36
TaskA02/Task2.py Normal file
View File

@ -0,0 +1,36 @@
def openFile(fileName,piesArray = ['[Pp ]', 'i', 'e', 's', '[ \t\n.,;!?]']):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
repCounter = 0
counter = 0
checkWord =[]
for i in row:
if i in piesArray[counter]:
if i != ' ' or counter != 0:
checkWord+=i
counter+=1
if len(checkWord) >= 5:
sum = 0
for z in checkWord:
if z in piesArray[sum]:
sum +=1
if sum ==4:
checkWord = []
counter = 0
repCounter += 1 # if in one row more than one Hamlet it will write the row only once
if repCounter == 1:
print(row.strip())
else:
checkWord = []
counter = 0
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

31
TaskA02/TaskAO2.py Normal file
View File

@ -0,0 +1,31 @@
import re
def openFile(fileName,piesArray1 = [' ', 'P', 'p', '('],
piesArray2 = ['i', 'e', 's'],
piesArray3 = ['\t', '\n', '.', ',', ';', '!', '?', ')']):
with open(fileName, "r", encoding="utf-8") as file:
file_contents = file.read()
for row in file:
piesArrayCounter = 0
repCounter = 0
counter = 0
checkWord = ''
for character in row:
if character == ' ':
checkWord+=character
if counter == 0 and checkWord == ' ':
if (character == 'P' or character == 'p'):
counter +=1
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('shakespeare.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('shakespeare.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,67 +0,0 @@
def checkFirstSymbol(character):
if character == 'P' or character == 'p' or character == ' ':
return character
else:
return None
def checkLastSymbol(character):
if (character == '\t'
or character == '\n'
or character == '.'
or character == ','
or character == ';'
or character == '!'
or character == ' '
or character == '?'
or character == '-'
or character == ')'):
return character
else:
return None
def openFile(fileName):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
lastWordSymbol = ''
counter = 0
checkWord = []
for i in row:
if lastWordSymbol == '' or lastWordSymbol == ' ':
if i == 'P' or i=='p':
checkWord+=i
lastWordSymbol = i
elif lastWordSymbol == checkFirstSymbol(lastWordSymbol):
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 'i' and i=='e':
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 'e' and i == 's':
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 's' and i == checkLastSymbol(i):
checkWord += i
lastWordSymbol = i
else:
checkWord=[]
lastWordSymbol=''
if (len(checkWord)>=5 and checkWord[0]==checkFirstSymbol(checkWord[0])
and checkWord[1] == 'i'
and checkWord[2] == 'e'
and checkWord[3] == 's'
and checkWord[4] == checkLastSymbol(checkWord[4])):
print(row, end ='')
break
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

2
TaskA02/test.py Normal file
View File

@ -0,0 +1,2 @@
str = r'[Pp ]ies '
print(len(str))

View File

@ -1,52 +0,0 @@
import sys
def checkNumber(letter):
if (letter == '0'
or letter == '1'
or letter == '2'
or letter == '3'
or letter == '4'
or letter == '5'
or letter == '6'
or letter == '7'
or letter == '8'
or letter == '9'):
return letter
else:
return None
def openFile(fileName):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
lastCharacter = ''
checkWord =''
allLine = ''
for letter in row:
if checkWord != '':
if letter == checkNumber(letter):
checkWord += letter
else:
allLine += checkWord
allLine += ' '
checkWord = ''
else:
if letter == checkNumber(letter):
checkWord += letter
if letter == '\n':
if allLine != '':
print(allLine)
allLine = ''
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,5 +1,5 @@
cd jfz34234 34 dfd gfd 5
34535
fsdflskf3jsdf3lk
fsdflskfjsdflk
fsdkfj sdf34fdfd
Firma powstała w 1992 r., z połączenia Authorware, Inc. (twórców pakietu Authorware) i MacroMind-Paracomp (producenta Macromind Director). W 1999 r. Macromedia zakupiła firmę Allaire i jej bi

View File

@ -1,2 +0,0 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\test1.in .\test1.out

View File

@ -1,8 +0,0 @@
Read a description of a 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: ./run.py fsa_description.arg < test1.in > test1.out

View File

@ -1,16 +0,0 @@
0 1 x
1 2 y
2 3 z
0 4 y
0 4 z
1 4 x
1 4 z
2 4 x
2 4 y
3 4 x
3 4 y
3 4 z
4 4 x
4 4 y
4 4 z
3

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split('\t')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test1.in'
# output_file = 'test1.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':
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,9 +0,0 @@
NO
YES
NO
NO
NO
NO
NO
NO
NO

View File

@ -1,9 +0,0 @@
xxyz
xyz
xy
zz
xxy
yzx
x
xyzz

View File

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

View File

@ -1,2 +0,0 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\test.in .\test.out

View File

@ -1,10 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string starts with "01" and ends with "01.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,12 +0,0 @@
0 1 0
0 3 1
3 3 0
3 3 1
1 3 0
1 2 1
2 4 1
4 4 1
4 5 0
5 5 0
2 5 0
5 2 1

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='2':
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,14 +0,0 @@
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO

View File

@ -1,14 +0,0 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

View File

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

View File

@ -1,9 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string starts with "10" and ends with "10.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,12 +0,0 @@
0 1 1
0 3 0
3 3 1
3 3 0
1 3 1
1 2 0
2 4 0
4 4 0
4 5 1
5 5 1
2 5 1
5 2 0

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='2':
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,14 +0,0 @@
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO

View File

@ -1,14 +0,0 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

View File

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

View File

@ -1,11 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string contains "0"
even number of times.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,4 +0,0 @@
0 1 0
1 1 1
1 0 0
0 0 1

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='0':
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,14 +0,0 @@
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES

View File

@ -1,14 +0,0 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

View File

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

View File

@ -1,11 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string contains "0"
odd number of times.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,4 +0,0 @@
0 1 0
1 1 1
1 0 0
0 0 1

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='1':
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,14 +0,0 @@
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO

View File

@ -1,14 +0,0 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

View File

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

View File

@ -1,4 +0,0 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\simple.in .\simple.out
or
python .\run.py .\fsa_description.arg .\polish_wiki_excerpt_only_digits.in .\polish_wiki_excerpt_only_digits.out

View File

@ -1,10 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskB00.
Create your own FSA description to check whether the line contains string '19DD', where D is a digit.
Save it to fsa_description.arg file.
FSA alphabet is '0123456789x'.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,55 +0,0 @@
0 1 1
0 0 2
0 0 0
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
0 0 x
1 1 0
1 1 1
1 2 9
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
1 0 x
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
2 3 7
2 3 8
2 3 9
2 3 0
2 0 x
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 0 x
4 4 0
4 4 1
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
4 4 x

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='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,6 +0,0 @@
NO
YES
NO
NO
YES
YES

View File

@ -1,6 +0,0 @@
3214545443
1910
19
xxx2190x
xxx21905x
1905x54545

View File

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

View File

@ -1,4 +0,0 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\simple.in .\simple.out
or
python .\run.py .\fsa_description.arg .\shakespeare_ascii_lower.in .\shakespeare_ascii_lower.out

View File

@ -1,9 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "hamlet" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,189 +0,0 @@
0 1 h
1 2 a
2 3 m
3 4 l
4 5 e
5 6 t
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 i
0 0 j
0 0 k
0 0 l
0 0 m
0 0 n
0 0 o
0 0 p
0 0 q
0 0 r
0 0 s
0 0 t
0 0 u
0 0 v
0 0 w
0 0 x
0 0 y
0 0 z
0 0
1 0
1 0 h
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
1 0 i
1 0 j
1 0 k
1 0 l
1 0 m
1 0 n
1 0 o
1 0 p
1 0 q
1 0 r
1 0 s
1 0 t
1 0 u
1 0 v
1 0 w
1 0 x
1 0 y
1 0 z
2 0
2 0 a
2 0 b
2 0 c
2 0 d
2 0 e
2 0 f
2 0 g
2 0 i
2 0 j
2 0 k
2 0 l
2 0 h
2 0 n
2 0 o
2 0 p
2 0 q
2 0 r
2 0 s
2 0 t
2 0 u
2 0 v
2 0 w
2 0 x
2 0 y
2 0 z
3 0 m
3 0 a
3 0 b
3 0 c
3 0 d
3 0 e
3 0 f
3 0 g
3 0 i
3 0 j
3 0 k
3 0
3 0 h
3 0 n
3 0 o
3 0 p
3 0 q
3 0 r
3 0 s
3 0 t
3 0 u
3 0 v
3 0 w
3 0 x
3 0 y
3 0 z
4 0 m
4 0 a
4 0 b
4 0 c
4 0 d
4 0
4 0 f
4 0 g
4 0 i
4 0 j
4 0 k
4 0 l
4 0 h
4 0 n
4 0 o
4 0 p
4 0 q
4 0 r
4 0 s
4 0 t
4 0 u
4 0 v
4 0 w
4 0 x
4 0 y
4 0 z
5 0 m
5 0 a
5 0 b
5 0 c
5 0 d
5 0 e
5 0 f
5 0 g
5 0 i
5 0 j
5 0 k
5 0 l
5 0 h
5 0 n
5 0 o
5 0 p
5 0 q
5 0 r
5 0 s
5 0
5 0 u
5 0 v
5 0 w
5 0 x
5 0 y
5 0 z
6 6 m
6 6 a
6 6 b
6 6 c
6 6 d
6 6 e
6 6 f
6 6 g
6 6 i
6 6 j
6 6 k
6 6 l
6 6 h
6 6 n
6 6 o
6 6 p
6 6 q
6 6 r
6 6 s
6 6 t
6 6 u
6 6 v
6 6 w
6 6 x
6 6 y
6 6 z
6 6

View File

@ -1,37 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
used_table = 'fsa_description.arg'
input_file = 'simple.in'
output_file = 'simple.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=='6':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,3 +0,0 @@
haml
hamlet
aaahamletbbb

View File

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

View File

@ -1,10 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "ophelia" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,216 +0,0 @@
0 1 o
1 2 p
2 3 h
3 4 e
4 5 l
5 6 i
6 7 a
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 h
0 0 i
0 0 j
0 0 k
0 0 l
0 0 m
0 0 n
0 0 p
0 0 q
0 0 r
0 0 s
0 0 t
0 0 u
0 0 v
0 0 w
0 0 x
0 0 y
0 0 z
0 0
1 0 a
1 0 h
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
1 0 i
1 0 j
1 0 k
1 0 l
1 0 m
1 0 n
1 0 o
1 0
1 0 q
1 0 r
1 0 s
1 0 t
1 0 u
1 0 v
1 0 w
1 0 x
1 0 y
1 0 z
2 0
2 0 a
2 0 b
2 0 c
2 0 d
2 0 e
2 0 f
2 0 g
2 0 i
2 0 j
2 0 k
2 0 l
2 0 m
2 0 n
2 0 o
2 0 p
2 0 q
2 0 r
2 0 s
2 0 t
2 0 u
2 0 v
2 0 w
2 0 x
2 0 y
2 0 z
3 0 m
3 0 a
3 0 b
3 0 c
3 0 d
3 0 l
3 0 f
3 0 g
3 0 i
3 0 j
3 0 k
3 0
3 0 h
3 0 n
3 0 o
3 0 p
3 0 q
3 0 r
3 0 s
3 0 t
3 0 u
3 0 v
3 0 w
3 0 x
3 0 y
3 0 z
4 0 m
4 0 a
4 0 b
4 0 c
4 0 d
4 0 e
4 0 f
4 0 g
4 0 i
4 0 j
4 0 k
4 0
4 0 h
4 0 n
4 0 o
4 0 p
4 0 q
4 0 r
4 0 s
4 0 t
4 0 u
4 0 v
4 0 w
4 0 x
4 0 y
4 0 z
5 0 m
5 0 a
5 0 b
5 0 c
5 0 d
5 0 e
5 0 f
5 0 g
5 0
5 0 j
5 0 k
5 0 l
5 0 h
5 0 n
5 0 o
5 0 p
5 0 q
5 0 r
5 0 s
5 0 t
5 0 u
5 0 v
5 0 w
5 0 x
5 0 y
5 0 z
6 0 m
6 0
6 0 b
6 0 c
6 0 d
6 0 e
6 0 f
6 0 g
6 0 i
6 0 j
6 0 k
6 0 l
6 0 h
6 0 n
6 0 o
6 0 p
6 0 q
6 0 r
6 0 s
6 0 t
6 0 u
6 0 v
6 0 w
6 0 x
6 0 y
6 0 z
7 7 m
7 7 a
7 7 b
7 7 c
7 7 d
7 7 e
7 7 f
7 7 g
7 7 i
7 7 j
7 7 k
7 7 l
7 7 h
7 7 n
7 7 o
7 7 p
7 7 q
7 7 r
7 7 s
7 7 t
7 7 u
7 7 v
7 7 w
7 7 x
7 7 y
7 7 z
7 7

View File

@ -1,37 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='7':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,3 +0,0 @@
oph
ophelia
xfdfdopheliafff

View File

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

View File

@ -1,10 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "juliet" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,189 +0,0 @@
0 1 j
1 2 u
2 3 l
3 4 i
4 5 e
5 6 t
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 h
0 0 i
0 0 k
0 0 l
0 0 m
0 0 n
0 0 o
0 0 p
0 0 q
0 0 r
0 0 s
0 0 t
0 0 u
0 0 v
0 0 w
0 0 x
0 0 y
0 0 z
0 0
1 0
1 0 a
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
1 0 i
1 0 j
1 0 k
1 0 l
1 0 m
1 0 n
1 0 o
1 0 p
1 0 q
1 0 r
1 0 s
1 0 t
1 0 h
1 0 v
1 0 w
1 0 x
1 0 y
1 0 z
2 0
2 0 a
2 0 b
2 0 c
2 0 d
2 0 e
2 0 f
2 0 g
2 0 i
2 0 j
2 0 k
2 0 m
2 0 h
2 0 n
2 0 o
2 0 p
2 0 q
2 0 r
2 0 s
2 0 t
2 0 u
2 0 v
2 0 w
2 0 x
2 0 y
2 0 z
3 0 m
3 0 a
3 0 b
3 0 c
3 0 d
3 0 e
3 0 f
3 0 g
3 0
3 0 j
3 0 k
3 0 l
3 0 h
3 0 n
3 0 o
3 0 p
3 0 q
3 0 r
3 0 s
3 0 t
3 0 u
3 0 v
3 0 w
3 0 x
3 0 y
3 0 z
4 0 m
4 0 a
4 0 b
4 0 c
4 0 d
4 0
4 0 f
4 0 g
4 0 i
4 0 j
4 0 k
4 0 l
4 0 h
4 0 n
4 0 o
4 0 p
4 0 q
4 0 r
4 0 s
4 0 t
4 0 u
4 0 v
4 0 w
4 0 x
4 0 y
4 0 z
5 0 m
5 0 a
5 0 b
5 0 c
5 0 d
5 0 e
5 0 f
5 0 g
5 0 i
5 0 j
5 0 k
5 0 l
5 0 h
5 0 n
5 0 o
5 0 p
5 0 q
5 0 r
5 0 s
5 0
5 0 u
5 0 v
5 0 w
5 0 x
5 0 y
5 0 z
6 6 m
6 6 a
6 6 b
6 6 c
6 6 d
6 6 e
6 6 f
6 6 g
6 6 i
6 6 j
6 6 k
6 6 l
6 6 h
6 6 n
6 6 o
6 6 p
6 6 q
6 6 r
6 6 s
6 6 t
6 6 u
6 6 v
6 6 w
6 6 x
6 6 y
6 6 z
6 6

View File

@ -1,37 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='6':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,3 +0,0 @@
juli
juliet
dgfdgjulietaaa

View File

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

View File

@ -1,10 +0,0 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "macbeth" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -1,216 +0,0 @@
0 1 m
1 2 a
2 3 c
3 4 b
4 5 e
5 6 t
6 7 h
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 h
0 0 i
0 0 j
0 0 k
0 0 l
0 0 n
0 0 0
0 0 p
0 0 q
0 0 r
0 0 s
0 0 t
0 0 u
0 0 v
0 0 w
0 0 x
0 0 y
0 0 z
0 0
1 0
1 0 h
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
1 0 i
1 0 j
1 0 k
1 0 l
1 0 m
1 0 n
1 0 o
1 0 p
1 0 q
1 0 r
1 0 s
1 0 t
1 0 u
1 0 v
1 0 w
1 0 x
1 0 y
1 0 z
2 0 h
2 0 a
2 0 b
2 0
2 0 d
2 0 e
2 0 f
2 0 g
2 0 i
2 0 j
2 0 k
2 0 l
2 0 m
2 0 n
2 0 o
2 0 p
2 0 q
2 0 r
2 0 s
2 0 t
2 0 u
2 0 v
2 0 w
2 0 x
2 0 y
2 0 z
3 0 m
3 0 a
3 0
3 0 c
3 0 d
3 0 e
3 0 f
3 0 g
3 0 i
3 0 j
3 0 k
3 0 l
3 0 h
3 0 n
3 0 o
3 0 p
3 0 q
3 0 r
3 0 s
3 0 t
3 0 u
3 0 v
3 0 w
3 0 x
3 0 y
3 0 z
4 0 m
4 0 a
4 0 b
4 0 c
4 0 d
4 0
4 0 f
4 0 g
4 0 i
4 0 j
4 0 k
4 0 l
4 0 h
4 0 n
4 0 o
4 0 p
4 0 q
4 0 r
4 0 s
4 0 t
4 0 u
4 0 v
4 0 w
4 0 x
4 0 y
4 0 z
5 0 m
5 0 a
5 0 b
5 0 c
5 0 d
5 0 e
5 0 f
5 0 g
5 0 i
5 0 j
5 0 k
5 0 l
5 0 h
5 0 n
5 0 o
5 0 p
5 0 q
5 0 r
5 0 s
5 0
5 0 u
5 0 v
5 0 w
5 0 x
5 0 y
5 0 z
6 0 m
6 0 a
6 0 b
6 0 c
6 0 d
6 0 e
6 0 f
6 0 g
6 0 i
6 0 j
6 0 k
6 0 l
6 0
6 0 n
6 0 o
6 0 p
6 0 q
6 0 r
6 0 s
6 0 t
6 0 u
6 0 v
6 0 w
6 0 x
6 0 y
6 0 z
7 7 m
7 7 a
7 7 b
7 7 c
7 7 d
7 7 e
7 7 f
7 7 g
7 7 i
7 7 j
7 7 k
7 7 l
7 7 h
7 7 n
7 7 o
7 7 p
7 7 q
7 7 r
7 7 s
7 7 t
7 7 u
7 7 v
7 7 w
7 7 x
7 7 y
7 7 z
7 7

View File

@ -1,37 +0,0 @@
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:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# 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(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=='7':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,3 +0,0 @@
macb
macbeth
xadadamacbethrff

View File

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

View File

@ -1,12 +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.

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,7 +0,0 @@
aaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
xyz
aba
a

View File

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

View File

@ -1,59 +0,0 @@
import sys
sys.setrecursionlimit(5000)
def write_answer(answer):
with open(output_file, 'a') as file:
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):
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 = '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:
if line_checking(row_input_file, '0'):
write_answer('YES')
else:
write_answer('NO')

View File

@ -1,16 +0,0 @@
0 1 x
1 2 y
2 3 z
0 4 y
0 4 z
1 4 x
1 4 z
2 4 x
2 4 y
3 4 x
3 4 y
3 4 z
4 4 x
4 4 y
4 4 z
3

View File

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

View File

@ -1,9 +0,0 @@
xxyz
xyz
xy
zz
xxy
yzx
x
xyzz

View File

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

View File

@ -1,7 +0,0 @@
0 1 a
1 0 a
1 2 b
2 4 c
1 3 b
3
4

View File

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

View File

@ -1,8 +0,0 @@
abc
ab
abcd
aaaabc
aaaaaaaabc
aaaaaaabc
zzz
aaaaaaabc

View File

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

View File

@ -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.

View File

@ -1,62 +0,0 @@
import sys
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):
with open(output_file, 'a') as file:
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):
take_all_possible_positions = []
for row_used_table in arg:
if len(row_used_table) != 1:
if position == row_used_table[0] and character == row_used_table[2]:
take_all_possible_positions.append(row_used_table[1])
return take_all_possible_positions
def what_is_the_ended_positions():
array = []
for row in arg:
if len(row) == 1:
array += row
return array
# used_table = 'test.arg'
# input_file = 'test.in'
# output_file = 'test.out'
# used_table = sys.argv[1]
input_file = sys.argv[1]
output_file = sys.argv[2]
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'):
write_answer('YES')
else:
write_answer('NO')

Some files were not shown because too many files have changed in this diff Show More