From 9f7a10407ac952f90081220d140ec2179b0eadde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 22:07:05 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A3=D1=80=D0=BE=D0=BA=201,=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20=D0=B8=D0=B7=20=D0=B4=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task1.py | 5 +++++ task2.py | 8 ++++++++ task3.py | 6 ++++++ task4.py | 5 +++++ task5.py | 17 +++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 task1.py create mode 100644 task2.py create mode 100644 task3.py create mode 100644 task4.py create mode 100644 task5.py diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..5faa170 --- /dev/null +++ b/task1.py @@ -0,0 +1,5 @@ +b = input().split(' ') +sum = 0 +for i in b: + sum = sum + float(i) +print(sum) diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..c5165e9 --- /dev/null +++ b/task2.py @@ -0,0 +1,8 @@ +sim1, sim2 = input().split('->')[0], input().split('->')[-1] +stroka = str() +for i in a: + if sim1 == i: + stroka = stroka + sim2 + else: + stroka = stroka + i +print(stroka) diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..e0e846e --- /dev/null +++ b/task3.py @@ -0,0 +1,6 @@ +c = input().split(' ') +stroka = str() +for i in c: + m = int(abs(float(i))) + stroka = stroka + str(m) + ' ' +print(stroka[:-1]) diff --git a/task4.py b/task4.py new file mode 100644 index 0000000..066a043 --- /dev/null +++ b/task4.py @@ -0,0 +1,5 @@ +a = input().split(' ') +summa = int() +for i in a: + summa = summa + float(i) ** 2 +print(summa) diff --git a/task5.py b/task5.py new file mode 100644 index 0000000..c9a1499 --- /dev/null +++ b/task5.py @@ -0,0 +1,17 @@ +alfavit = "abcdefghijklmnopqrstuvwxyz" +a = input().split(' ') +kod = int(input()) +b = ''.join(a) +stroka = str() +for i in b: + k = 0 + for j in alfavit: + if i == j: + if k + kod >= len(alfavit): + stroka = stroka + alfavit[k+kod-26] + else: + stroka = stroka + alfavit[k+kod] + else: + pass + k += 1 +print(stroka) From fa76ad2f580964d54bd1dc4f68532726e74c7a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 19 Mar 2023 11:53:24 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=202=20=D0=B8=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task2.py | 23 +++++++++++++++-------- task5.py | 19 +++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/task2.py b/task2.py index c5165e9..7e0d5b3 100644 --- a/task2.py +++ b/task2.py @@ -1,8 +1,15 @@ -sim1, sim2 = input().split('->')[0], input().split('->')[-1] -stroka = str() -for i in a: - if sim1 == i: - stroka = stroka + sim2 - else: - stroka = stroka + i -print(stroka) +stroka = input() +while True: + str_sim2 = str() + a = '' + a = input() + if a == '': + break + sim1, sim2 = a.split('->')[0], a.split('->')[1] + for i in stroka: + if i == sim1: + str_sim2 = str_sim2 + sim2 + else: + str_sim2 = str_sim2 + i + stroka = str_sim2 + print(stroka) diff --git a/task5.py b/task5.py index c9a1499..320c0d7 100644 --- a/task5.py +++ b/task5.py @@ -2,16 +2,11 @@ a = input().split(' ') kod = int(input()) b = ''.join(a) -stroka = str() +stroka = '' for i in b: - k = 0 - for j in alfavit: - if i == j: - if k + kod >= len(alfavit): - stroka = stroka + alfavit[k+kod-26] - else: - stroka = stroka + alfavit[k+kod] - else: - pass - k += 1 -print(stroka) + index = alfavit.find(i) + k = index + kod + while k >= len(alfavit): + k = k - len(alfavit) + stroka = stroka + alfavit[k] +print(stroka)) From 87a9acdb544e389fad416307883d8e1d4f4f0d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 1 Apr 2023 18:19:29 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=88=D1=83=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=20=D1=81=20=D1=82=D0=B0=D0=BA=D0=B8=D0=BC=20=D0=BE=D0=BF=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=94=D0=97=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DZ.2 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 DZ.2 diff --git a/DZ.2 b/DZ.2 new file mode 100644 index 0000000..adde5bf --- /dev/null +++ b/DZ.2 @@ -0,0 +1,39 @@ +import math +import sys +path1 = r'C:\Users\User\PycharmProjects\pythonProject\Prov.py.lzw' +path2 = r'C:\Users\User\PycharmProjects\pythonProject\out_fail' + +if not (2 <= len(sys.argv) <= 3): + print('Usage: ', sys.argv[0], 'input_file') +outpath = sys.argv[2] if len(sys.argv) == 3 else sys.argv[1] + '.lzw' + +with open(sys.argv[1], 'rb') as file: + data = file.read() + +dictionary = {i:(i,) for i in range(256)} +sequens = list() +i = 0 +with open(outpath, 'wb') as file: + while i < len(data): + if sequens == []: + n = len(dictionary) + else: + n = len(dictionary) + 1 + nbits = math.ceil(math.log2(n)) + nbytes = nbits // 8 + if nbits % 8 != 0: + nbytes += 1 + slice_dan = data[i : i + nbytes] + sym = int.from_bytes(slice_dan, 'little') + if sym == len(dictionary): + ch = len(sequens) - 1 if len(sequens) > 1 else 1 + new_sequence = sequens + sequens[:ch] + else: + new_sequence = list(dictionary[sym]) + file.write(bytearray(new_sequence)) + if sequens == []: + pass + else: + dictionary[len(dictionary)] = tuple(sequens + new_sequence[-1:]) + i += nbytes + sequens = new_sequence