From 821e297299501ecb94784fce804af1b2a944adab Mon Sep 17 00:00:00 2001 From: stud203799 Date: Tue, 14 Apr 2026 19:17:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks_on_python/N21_long_subseq.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tasks_on_python/N21_long_subseq.py b/tasks_on_python/N21_long_subseq.py index fb53f93..29b8551 100644 --- a/tasks_on_python/N21_long_subseq.py +++ b/tasks_on_python/N21_long_subseq.py @@ -1,20 +1,24 @@ # №21. longest_increasing_subsequence(arr: list) -> list # Найти самую длинную возрастающую подпоследовательность (не обязательно непрерывную). -# def long_inc_subseq(a: list): -a = [10, 9, 2, 5, 3, 7, 101, 18] -av = [] -for i in range(len(a)): - if i == len(a)-1: # цикл на последней итерации - if a[i] > av[-1]: - av.append(a[i]) +def long_inc_subseq(a: list): + av = [] + for i in range(len(a)): + if len(a) == 1: + av.append(a[0]) break - else: - break - if a[i] > a[i+1]: - av.append(a[i]) -print(av) + if i == len(a)-1: # цикл на последней итерации + if av != []: # пустой ли цикл в конце + if a[i] > av[-1]: + av.append(a[i]) + break + else: + av.append(a[i]) + else: + if a[i] < a[i+1]: + av.append(a[i]) + print(av) print("Введите последовательность чисел через пробел") -# long_inc_subseq(input().split()) \ No newline at end of file +long_inc_subseq([int(i) for i in input().split()]) \ No newline at end of file