Login
A   A   A  
welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

街景
2026-04-01 06:06:55
溫度26℃ 濕度95% 氣壓1012.00hPa
2026-04-01 04:14:58
閃電34km (0)
2026-03-31 20:58:45
閃電12km (2)
2026-03-31 20:31:41
閃電24km (0)
2026-03-31 20:25:33
閃電24km (0)
2026-03-31 20:19:10
閃電31km (0)
2026-03-31 19:38:22
閃電10km (0)
2026-03-31 19:36:20
閃電10km (3)
2026-03-31 19:34:47
閃電14km (1)
2026-03-31 13:10:55
閃電20km (0)
2026-03-30 14:00:51
閃電6km (0)

Find the longest increasing subsequence.

icon

Home>ICT>Python by ...>Find the l...

Find the longest increasing subsequence in a data file.

1# Author: HUANG KWUN HOI (SKHBBSS, class 4D)
2# Last modified: 2020.9.8
3file1=open('data2.txt', 'r')
4list1=[]
5list2=[]
6longest_series=[]
7x=0
8current_datum=0
9next_datum=0
10previous_longest_series_length=0
11current_series_length=0
12for data in file1:
13 a=data
14 b=a.split(',')
15 next_datum=float(b[1])
16 list1.append(current_datum)
17 if x==0:
18 del list1[0]
19 x=1
20 if current_datum>=next_datum:
21 previous_longest_series_length=int(len(longest_series))
22 current_series_length=int(len(list1))
23 if current_series_length>previous_longest_series_length:
24 longest_series=list1.copy()
25 list2=list1.copy()
26 list1.clear()
27 else:
28 list2=list1.copy()
29 second_last_datum=current_datum
30 current_datum=next_datum
31file1.close()
32if current_datum>second_last_datum:
33 list2.append(current_datum)
34 current_series_length=int(len(list2))
35 if current_series_length>previous_longest_series_length:
36 longest_series=list2.copy()
37print(longest_series, ' (', int(len(longest_series)), 'Days)' )

Download source code

Download data file

welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

街景
2026-04-01 06:06:55
溫度26℃ 濕度95% 氣壓1012.00hPa
2026-04-01 04:14:58
閃電34km (0)
2026-03-31 20:58:45
閃電12km (2)
2026-03-31 20:31:41
閃電24km (0)
2026-03-31 20:25:33
閃電24km (0)
2026-03-31 20:19:10
閃電31km (0)
2026-03-31 19:38:22
閃電10km (0)
2026-03-31 19:36:20
閃電10km (3)
2026-03-31 19:34:47
閃電14km (1)
2026-03-31 13:10:55
閃電20km (0)
2026-03-30 14:00:51
閃電6km (0)
 ⇧