From 6e30045b9c1bbbd246c3aaf8aed93ac32c0ede12 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 8 Nov 2020 19:09:25 +0100 Subject: [PATCH] A04 working --- TaskA04/run.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/TaskA04/run.py b/TaskA04/run.py index 1e2300a..7d8a903 100644 --- a/TaskA04/run.py +++ b/TaskA04/run.py @@ -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) \ No newline at end of file