A04 working
This commit is contained in:
parent
5d4c7215d3
commit
6e30045b9c
@ -11,6 +11,7 @@ def find_indexes(word):
|
||||
|
||||
|
||||
def find_max_substring(indexes, word):
|
||||
output = ""
|
||||
substring = []
|
||||
max_substring = []
|
||||
substring.append(word[indexes[0]])
|
||||
@ -22,32 +23,37 @@ def find_max_substring(indexes, word):
|
||||
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 len(substring) > len(max_substring):
|
||||
return substring
|
||||
else:
|
||||
return max_substring
|
||||
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:
|
||||
indexes = find_indexes(sub)
|
||||
if indexes:
|
||||
digits = "".join(find_max_substring(indexes, sub))
|
||||
output += digits + " "
|
||||
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:
|
||||
return output.rstrip()
|
||||
output = output.replace(" ", " ")
|
||||
return print(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))
|
||||
max_line_digits(line)
|
Loading…
Reference in New Issue
Block a user