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):
|
def find_max_substring(indexes, word):
|
||||||
|
output = ""
|
||||||
substring = []
|
substring = []
|
||||||
max_substring = []
|
max_substring = []
|
||||||
substring.append(word[indexes[0]])
|
substring.append(word[indexes[0]])
|
||||||
@ -22,32 +23,37 @@ def find_max_substring(indexes, word):
|
|||||||
if prev+1 == curr:
|
if prev+1 == curr:
|
||||||
substring.append(word[curr])
|
substring.append(word[curr])
|
||||||
else:
|
else:
|
||||||
|
output += "".join(substring) + " "
|
||||||
if len(max_substring) < len(substring):
|
if len(max_substring) < len(substring):
|
||||||
max_substring = substring.copy()
|
max_substring = substring.copy()
|
||||||
substring.clear()
|
substring.clear()
|
||||||
substring.append(word[curr])
|
substring.append(word[curr])
|
||||||
if len(substring) > len(max_substring):
|
if output == "" and len(substring) > 0:
|
||||||
return substring
|
output += "".join(substring) + " "
|
||||||
else:
|
return output.rstrip()
|
||||||
return max_substring
|
|
||||||
|
|
||||||
|
|
||||||
def max_line_digits(line):
|
def max_line_digits(line):
|
||||||
output = ""
|
output = ""
|
||||||
substrings = line.split(' ')
|
substrings = line.split(' ')
|
||||||
for sub in substrings:
|
for sub in substrings:
|
||||||
indexes = find_indexes(sub)
|
number = []
|
||||||
if indexes:
|
for s in sub:
|
||||||
digits = "".join(find_max_substring(indexes, sub))
|
char = ord(s)
|
||||||
output += digits + " "
|
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 == '':
|
if output == '':
|
||||||
return False
|
return False
|
||||||
else:
|
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:
|
for line in sys.stdin:
|
||||||
if max_line_digits(line):
|
max_line_digits(line)
|
||||||
print(max_line_digits(line))
|
|
Loading…
Reference in New Issue
Block a user