A04
This commit is contained in:
parent
31b2e97554
commit
5d4c7215d3
@ -18,6 +18,4 @@ def is_date_in_line(line):
|
||||
|
||||
for line in sys.stdin:
|
||||
if is_date_in_line(line):
|
||||
print(line.rstrip('\n'))
|
||||
|
||||
|
||||
print(line.rstrip('\n'))
|
0
TaskA04/Makefile
Normal file
0
TaskA04/Makefile
Normal file
2
TaskA04/run
Normal file
2
TaskA04/run
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
python TaskA04/run.py "$@"
|
53
TaskA04/run.py
Normal file
53
TaskA04/run.py
Normal file
@ -0,0 +1,53 @@
|
||||
import sys
|
||||
|
||||
|
||||
def find_indexes(word):
|
||||
indexes = []
|
||||
for index, w in enumerate(word):
|
||||
char = ord(w)
|
||||
if 48 <= int(char) <= 57:
|
||||
indexes.append(index)
|
||||
return indexes
|
||||
|
||||
|
||||
def find_max_substring(indexes, word):
|
||||
substring = []
|
||||
max_substring = []
|
||||
substring.append(word[indexes[0]])
|
||||
|
||||
for i in range(1, len(indexes), 1):
|
||||
prev = indexes[i-1]
|
||||
curr = indexes[i]
|
||||
|
||||
if prev+1 == curr:
|
||||
substring.append(word[curr])
|
||||
else:
|
||||
if len(max_substring) < len(substring):
|
||||
max_substring = substring.copy()
|
||||
substring.clear()
|
||||
substring.append(word[curr])
|
||||
if len(substring) > len(max_substring):
|
||||
return substring
|
||||
else:
|
||||
return max_substring
|
||||
|
||||
|
||||
def max_line_digits(line):
|
||||
output = ""
|
||||
substrings = line.split(' ')
|
||||
for sub in substrings:
|
||||
indexes = find_indexes(sub)
|
||||
if indexes:
|
||||
digits = "".join(find_max_substring(indexes, sub))
|
||||
output += digits + " "
|
||||
|
||||
if output == '':
|
||||
return False
|
||||
else:
|
||||
return output.rstrip()
|
||||
|
||||
lines = ['34234 34 dfd gfd 5', '34535','fsdflskfjsdflk', 'fsdkfj sdf34fdfd']
|
||||
|
||||
for line in sys.stdin:
|
||||
if max_line_digits(line):
|
||||
print(max_line_digits(line))
|
Loading…
Reference in New Issue
Block a user