This commit is contained in:
doasdsk 2023-11-27 13:18:58 +01:00
parent 76e8672177
commit a01e160be8
36 changed files with 205 additions and 0 deletions

3
TaskD01/description.txt Normal file
View File

@ -0,0 +1,3 @@
Write a program to find lines containing the word "Hamlet".
Do use regular expressions.

14
TaskD01/run.py Normal file
View File

@ -0,0 +1,14 @@
import sys
inFile = sys.argv[1]
outFile = sys.argv[2]
# inFile = 'simple.in'
# outFile = 'simple.out'
with open(inFile, 'r', encoding='utf-8') as inputFile, open(outFile, 'w', encoding='utf-8') as outputFile:
for line in inputFile:
if 'hamlet' in line.lower():
outputFile.write(line)
# print(line, end='')

0
TaskD01/shakespeare.exp Normal file
View File

0
TaskD01/shakespeare.in Normal file
View File

0
TaskD01/shakespeare.out Normal file
View File

2
TaskD01/simple.exp Normal file
View File

@ -0,0 +1,2 @@
Here comes Hamlet
Hamlet Hamlet again

3
TaskD01/simple.in Normal file
View File

@ -0,0 +1,3 @@
Here comes Hamlet
ABC
Hamlet Hamlet again

2
TaskD01/simple.out Normal file
View File

@ -0,0 +1,2 @@
Here comes Hamlet
Hamlet Hamlet again

4
TaskD02/description.txt Normal file
View File

@ -0,0 +1,4 @@
Write a program to find lines containing the word "pies" separated by spaces.
The word does not need to have space on the left if it is the line beginning or space on the right if it is line ending.
Return line no matter of word "pies" casing.
Do use regular expressions.

View File

View File

View File

19
TaskD02/run.py Normal file
View File

@ -0,0 +1,19 @@
import sys
import re
inFile = sys.argv[1]
outFile = sys.argv[2]
with open(inFile, "r", encoding="utf-8") as sampleCheck, open(outFile, 'w', encoding='utf-8') as outputFile:
pattern = re.compile(r'(\bp\w*ies\b)', re.IGNORECASE)
for line in sampleCheck:
match = re.search(pattern, line)
if match:
outputFile.write(line)
print(line, end='')

3
TaskD02/simple.exp Normal file
View File

@ -0,0 +1,3 @@
Pies ma Alę
Kot i pies to zwierzęta
pies

5
TaskD02/simple.in Normal file
View File

@ -0,0 +1,5 @@
Pies ma Alę
Ala ma psa
tu nic nie ma
Kot i pies to zwierzęta
pies

3
TaskD02/simple.out Normal file
View File

@ -0,0 +1,3 @@
Pies ma Alę
Kot i pies to zwierzęta
pies

4
TaskD03/description.txt Normal file
View File

@ -0,0 +1,4 @@
Write a program to find lines containing date from 1900 to 1999 in format '19XX r.' no matter what on the left or right of the expression.
Note that part ' r.' is obligatory.
Do use regular expressions.

View File

View File

View File

16
TaskD03/run.py Normal file
View File

@ -0,0 +1,16 @@
import re
import sys
inFile = sys.argv[1]
outFile = sys.argv[2]
with open(inFile, 'r', encoding="utf-8") as sampleCheck, open(outFile, 'w', encoding='utf-8') as outputFile:
pattern = re.compile(r'19[0-9][0-9] r\.')
for line in sampleCheck:
match = re.search(pattern, line)
if match:
outputFile.write(line)
print(line, end='')

3
TaskD03/simple.exp Normal file
View File

@ -0,0 +1,3 @@
Kiedyś był 1934 r.
Kiedyś był 1934 r.fsdfsdfsdf
1934 r. to jakaś data

5
TaskD03/simple.in Normal file
View File

@ -0,0 +1,5 @@
Kiedyś był 1934 r.
Kiedyś był 1934 r.fsdfsdfsdf
Kiedyś był 1935 rok
1934 r. to jakaś data
1934 to też jakaś data

3
TaskD03/simple.out Normal file
View File

@ -0,0 +1,3 @@
Kiedyś był 1934 r.
Kiedyś był 1934 r.fsdfsdfsdf
1934 r. to jakaś data

3
TaskD04/description.txt Normal file
View File

@ -0,0 +1,3 @@
Write a program to find all maximum substrings of digits.
Return only these substrings separated by spaces in their order.
Do use regular expressions.

View File

View File

16
TaskD04/run.py Normal file
View File

@ -0,0 +1,16 @@
import re
import sys
inFile = sys.argv[1]
outFile = sys.argv[2]
with open(inFile, "r", encoding="utf-8") as sampleCheck, open(outFile, 'w', encoding='utf-8') as outputFile:
pattern = re.compile(r'\b\d+\b')
for line in sampleCheck:
matches = re.findall(pattern, line)
if matches:
result = ' '.join(matches)
outputFile.write(result + '\n')
print(result)

4
TaskD04/simple.exp Normal file
View File

@ -0,0 +1,4 @@
34234 34 5
34535
34
1992 1999

5
TaskD04/simple.in Normal file
View File

@ -0,0 +1,5 @@
34234 34 dfd gfd 5
34535
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

3
TaskD04/simple.out Normal file
View File

@ -0,0 +1,3 @@
34234 34 5
34535
1992 1999

36
TaskE00/description.txt Normal file
View File

@ -0,0 +1,36 @@
Liczby podzielne przez 5
========================
Napisać program, który wczytuje kolejne wiersze ze standardowego
wejścia i analizuje każdy wiersz (bez znaku końca wiersza). Należy w
jak największym stopniu wykorzystać wyrażenia regularne (np. nie wolno
użyć negacji jako operacji w danym języku programowania, jeśli da się
to wyrazić w samym wyrażeniu regularnym). Tam, gdzie to możliwe należy
użyć pojedynczego wyrażenia regularnego.
Write a program, which loads consecutive lines from standard input
and analyze every line (with no newline character). You should
use regular expressions to the greatest extent possible (e.g. you
can not use negation in the programming language if it is
possible to express the same in regular expression). Wherever possible,
use one regular expression.
Dla każdego napisu należy sprawdzić, czy zadany napis jest liczbą całkowitą
podzielną przez 5. Napis nie powinien zawierać zer nieznaczących.
Jeśli napis spełnia tak określony warunek, należy wypisać na
standardowym wyjściu 'yes', w przeciwnym razie — 'no'.
For each string check, if the given string is an integer divisible by 5.
The string should not contain leading zeros.
If the string fulfills the condition, you should print 'yes' on the
standard output and 'no' otherwise.
UWAGA! Zadanie przeznaczone dla studentów, których numer indeksu
dzieli się przez 10 z resztą 0.
Attention. The task is for students whose students id remainder of the division by 10 is 0.
POINTS: 1
DEADLINE: 2021-12-04 23:59:59
REMAINDER: 0/10

19
TaskE00/run.py Normal file
View File

@ -0,0 +1,19 @@
import re
import sys
def is_divisible_by_5(s):
pattern = re.compile(r'^-?[1-9][0-9]*[05]$')
return bool(re.match(pattern, s))
inFile = sys.argv[1]
outFile = sys.argv[2]
with open(inFile, 'r', encoding='utf-8') as inputFile, open(outFile, 'w', encoding='utf-8') as outputFile:
lines = inputFile.readlines()
for line in lines:
line = line.strip()
result = "yes" if is_divisible_by_5(line) else "no"
outputFile.write(result+'\n')
# print(result)

10
TaskE00/test.exp Normal file
View File

@ -0,0 +1,10 @@
yes
yes
no
yes
no
no
yes
no
yes
no

10
TaskE00/test.in Normal file
View File

@ -0,0 +1,10 @@
-1005
-50
-76
0
00
01000
1000
353
465
@!q

10
TaskE00/test.out Normal file
View File

@ -0,0 +1,10 @@
yes
yes
no
no
no
no
yes
no
yes
no