54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
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))
|