59 lines
1.4 KiB
Python
59 lines
1.4 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):
|
|
output = ""
|
|
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:
|
|
output += "".join(substring) + " "
|
|
if len(max_substring) < len(substring):
|
|
max_substring = substring.copy()
|
|
substring.clear()
|
|
substring.append(word[curr])
|
|
if output == "" and len(substring) > 0:
|
|
output += "".join(substring) + " "
|
|
return output.rstrip()
|
|
|
|
|
|
def max_line_digits(line):
|
|
output = ""
|
|
substrings = line.split(' ')
|
|
for sub in substrings:
|
|
number = []
|
|
for s in sub:
|
|
char = ord(s)
|
|
if 48 <= int(char) <= 57:
|
|
number.append(s)
|
|
else:
|
|
if number and number[-1] != " ":
|
|
number.append(" ")
|
|
if len(number) > 0:
|
|
output += "".join(number) + " "
|
|
|
|
if output == '':
|
|
return False
|
|
else:
|
|
output = output.replace(" ", " ")
|
|
return print(output.rstrip())
|
|
|
|
|
|
for line in sys.stdin:
|
|
max_line_digits(line) |