Compare commits

..

5 Commits

Author SHA1 Message Date
29e223fe0d F 2024-01-07 12:16:30 +01:00
8369543e6f Merge https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2024-01-03 22:46:15 +01:00
1129cd6540 Task description fix. 2023-12-29 19:43:44 +01:00
023285f6ab Fixes 2023-12-11 22:16:59 +01:00
5cb32d1aa0 Before labs 5 2023-12-11 00:03:25 +01:00
52 changed files with 850343 additions and 14 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -248,3 +248,79 @@ E10 - E36 - po jedno dla każdego
E37 - E43 - po jedno dla każdego
E44 - E48 - po jedno dla każdego
## Zajęcia 5 11.12.2023 Wyrażenia regularne 3
F00 - F05 - do wykonania przez każdego
Proszę o przekopiowanie sobie pliku polish_wiki_excerpt.in z zadania F00 do katalogów z pozostałymi zadaniami
#### 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)

View File

@ -15,16 +15,15 @@ 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 wydobyć zadany napis jest numerem telefonu.
Dla każdego napisu należy wskazać czy zadany napis jest numerem telefonu.
Zakładamy, że numer telefonu składa się z dwóch cyfr opcjonalnie
poprzedzonych zerem, po których następuje spacja i 7 cyfr w formacie
N-NNN-NNN. Jeśli napis nie spełnia podanych warunków, należy wypisać
"<NONE>".
N-NNN-NNN. Jeśli napis spełnia podane warunki, należy wypisać
"yes", w przeciwnym wypadku "no".
For each string, extract a phone number. We assume, that the phone
For each string, indicate whether it is a phone number. We assume, that the phone
number consists of two digits (optionally prefixed by zero), followed
by space and 7 digits in N-NNN-NNN format. If the string does
not fulfill the condition, print "<NONE>".
by space and 7 digits in N-NNN-NNN format. If the string fulfills the condition, print "yes", otherwise "no".
UWAGA! Zadanie przeznaczone dla studentów, których numer indeksu
dzieli się przez 27 z resztą 20.

21
TaskF00/description.txt Normal file
View File

@ -0,0 +1,21 @@
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.
Write a program to substitute all 4-digits string to 4-characters string.
In the substituted string "0" should change to "a", "1" should change to "b", "2" should change to "c", etc.
E.g. "1162" should change to "bbgc".
In this task digit means [0-9] class.
POINTS: 2
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because one or more lines are too long

50000
TaskF00/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

16
TaskF00/run.py Normal file
View File

@ -0,0 +1,16 @@
import re
import sys
def num_to_lett(match):
word = match.group(0)
letters = []
dict_mapping = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
numbers = list(word)
for number in numbers:
letters.append(dict_mapping[int(number)])
new_word = ''.join(letters)
return new_word
for line in sys.stdin:
modified_line = re.sub(r'[0-9]{4}', num_to_lett, line)
print(modified_line.strip())

3
TaskF00/simple.exp Normal file
View File

@ -0,0 +1,3 @@
dece 34 dfd gfd 5
f33sdfsdbcdedsfsdf
3r

3
TaskF00/simple.in Normal file
View File

@ -0,0 +1,3 @@
3424 34 dfd gfd 5
f33sdfsd1234dsfsdf
3r

3
TaskF00/simple.out Normal file
View File

@ -0,0 +1,3 @@
dece 34 dfd gfd 5
f33sdfsdbcdedsfsdf
3r

22
TaskF01/description.txt Normal file
View File

@ -0,0 +1,22 @@
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.
For each word with at least one lower case letter and one capital letter
change every lower case letter to capital case and change every capital case
letter to lower. In this task word means the string of "\w" metacharacters,
lower case letter is [a-ząćęłńóśźż] class,
capital case letter is [A-ZĄĆĘŁŃÓŚŹŻ] class.
POINTS: 2
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because one or more lines are too long

50000
TaskF01/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

View File

16
TaskF01/run.py Normal file
View File

@ -0,0 +1,16 @@
import re
import sys
def num_to_lett(match):
word = match.group(0)
letters = []
dict_mapping = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
numbers = list(word)
for number in numbers:
letters.append(dict_mapping[int(number)])
new_word = ''.join(letters)
return new_word
for line in sys.stdin:
modified_line = re.sub(r'[0-9]{4}', num_to_lett, line)
print(modified_line.strip())

3
TaskF01/simple.exp Normal file
View File

@ -0,0 +1,3 @@
ala mA KOTa
lallaa
żUK

3
TaskF01/simple.in Normal file
View File

@ -0,0 +1,3 @@
ala Ma kotA
lallaa
Żuk

0
TaskF01/simple.out Normal file
View File

23
TaskF02/description.txt Normal file
View File

@ -0,0 +1,23 @@
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.
For each line write 4 digits separated by space "A B C D", where
A stands for all lower case letters, B stands for
all capital case letters, C stand for digit,
D stands for all remaining characters excluding newline.
In this task, lower case letter is [a-ząćęłńóśźż] class,
capital case letter is [A-ZĄĆĘŁŃÓŚŹŻ] class.
POINTS: 1
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because it is too large Load Diff

50000
TaskF02/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

14
TaskF02/run.py Normal file
View File

@ -0,0 +1,14 @@
import re
import sys
def analyze_line(line):
lowercase_letters = re.findall(r'[a-ząćęłńóśźż]', line)
uppercase_letters = re.findall(r'[A-ZĄĆĘŁŃÓŚŹŻ]', line)
digits = re.findall(r'\d', line)
remaining_characters = re.findall(r'[^a-zA-ZĄ-Ż0-9\n]', line)
result = f'{len(lowercase_letters)} {len(uppercase_letters)} {len(digits)} {len(remaining_characters)}'
return result
for line in sys.stdin:
print(analyze_line(line))

3
TaskF02/simple.exp Normal file
View File

@ -0,0 +1,3 @@
7 2 0 2
6 0 0 0
6 1 1 2

3
TaskF02/simple.in Normal file
View File

@ -0,0 +1,3 @@
ala Ma kotA
lallaa
Mam 2 żuki

3
TaskF02/simple.out Normal file
View File

@ -0,0 +1,3 @@
7 2 0 2
6 0 0 0
5 1 1 2

24
TaskF03/description.txt Normal file
View File

@ -0,0 +1,24 @@
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.
For each line write 2 digits separated by space "A B", where
A stands for all words starting with lower case letter,
B stands for all words starting with capital case letter,
In this task word means a string of "\w" metacharacters,
lower case letter is [a-ząćęłńóśźż] class,
capital case letter is [A-ZĄĆĘŁŃÓŚŹŻ] class capital case letter is [A-ZĄĆĘŁŃÓŚŹŻ] class.
POINTS: 1
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because it is too large Load Diff

50000
TaskF03/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

13
TaskF03/run.py Normal file
View File

@ -0,0 +1,13 @@
import re
import sys
def analyze_line(line):
lowercase_words = re.findall(r'\b[a-ząćęłńóśźż]\w*\b', line)
uppercase_words = re.findall(r'\b[A-ZĄĆĘŁŃÓŚŹŻ]\w*\b', line)
result = f'{len(lowercase_words)} {len(uppercase_words)}'
return result
for line in sys.stdin:
print(analyze_line(line))

2
TaskF03/simple.exp Normal file
View File

@ -0,0 +1,2 @@
2 1
1 0

2
TaskF03/simple.in Normal file
View File

@ -0,0 +1,2 @@
Żmija i żuk.
3daniowy obiad

2
TaskF03/simple.out Normal file
View File

@ -0,0 +1,2 @@
2 0
1 0

20
TaskF04/description.txt Normal file
View File

@ -0,0 +1,20 @@
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.
Write the input line with the second digits string deleted.
Digit is a [0-9] class.
POINTS: 1
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because one or more lines are too long

50000
TaskF04/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

View File

13
TaskF04/run.py Normal file
View File

@ -0,0 +1,13 @@
import re
""" import sys
for line in sys.stdin:
stripped_line = line.strip()
print(re.sub(r'(\D*\d+\D*)\d+', r'\1\2', stripped_line, count=1)) """
print(re.search(r'\d+ \d+', 'ala ma 41 41 kota'))
print(re.search(r' \d+ \d+', 'ala ma 41 123 kota'))
print(re.search(r' (\d+) \1', 'ala ma 41 41 kota'))
print(re.search(r' (\d+) \1', 'ala ma 41 123 kota'))

3
TaskF04/simple.exp Normal file
View File

@ -0,0 +1,3 @@
Mam 2 jabłka i banananów.
Mam 2 jabłka i banananów oraz 20 gruszek.
Widziałem 2 bociany.

3
TaskF04/simple.in Normal file
View File

@ -0,0 +1,3 @@
Mam 2 jabłka i 35 banananów.
Mam 2 jabłka i 35 banananów oraz 20 gruszek.
Widziałem 2 bociany.

0
TaskF04/simple.out Normal file
View File

22
TaskF05/description.txt Normal file
View File

@ -0,0 +1,22 @@
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.
Write the input line with the third word changed to "xxx" string.
The number of "x" in the "xxx" string should be the same as the
the number of characters in the input string.
In this task, a word means a string of "\w" metacharacters.
POINTS: 2
DEADLINE: 2024-01-07 23:59:59

File diff suppressed because one or more lines are too long

50000
TaskF05/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

100000
TaskF05/polish_wiki_excerpt.out Normal file

File diff suppressed because one or more lines are too long

12
TaskF05/run.py Normal file
View File

@ -0,0 +1,12 @@
import re
import sys
for line in sys.stdin:
stripped_line = line.strip()
print(re.sub(r'(\b\w+\b\s+\b\w+\b\s+)(\b\w+\b)', r'\1' + 'x' * len(re.findall(r'\w', line)), line, count=1))

2
TaskF05/simple.exp Normal file
View File

@ -0,0 +1,2 @@
Mam 2 xxxxxx i 35 banananów.
Widziałem 2 xxxxxxx.

2
TaskF05/simple.in Normal file
View File

@ -0,0 +1,2 @@
Mam 2 jabłka i 35 banananów.
Widziałem 2 bociany.

4
TaskF05/simple.out Normal file
View File

@ -0,0 +1,4 @@
Mam 2 xxxxxxxxxxxxxxxxxxxxxxxka i 35 banananĂłw.
WidziaĹem 2 xxxxxxxxxxxxxxxxx.

View File

@ -41,7 +41,7 @@ def get_index():
def is_task_set_correct(dir, task_set):
try:
with open(Path(dir, f'{task_set}.out')) as f_out, open(Path(dir, f'{task_set}.exp')) as f_exp:
with open(Path(dir, f'{task_set}.out'),encoding='utf-8') as f_out, open(Path(dir, f'{task_set}.exp'),encoding='utf-8') as f_exp:
f_out_lines = ''.join(f_out.readlines())
f_exp_lines = ''.join(f_exp.readlines())
return f_out_lines == f_exp_lines