Cześć, potrzebuje pomocy w zrobieniu schematu blokowego algorytmu. Narazie mam to:
Start. --> Wczytaj String --> idx_prev_delimiter = -1 idx_before = -1 idx_after = -1 max_length = 0 current_length = 0 --> string[i]==' ' || string[i]==',' || string[i]=='.' -->. if current lenght > max length -----(dla prawdy)--> max_length = current_length idx_after = i idx_before = idx_prev_delimiter (dla fałszu )
Dalej nwm jak rozpisać, myśle, ze jest czytelne.
def string_from_file(path):
with open(path) as f:
string = f.read()
return string
def longest_word(string): # complexity: O(n)
delimeters = {'.', ' ', ','}
idx_prev_delimiter = -1
idx_before = -1
idx_after = -1
max_length = 0
current_length = 0
for i in range(len(string)):
if string[i] in delimeters:
if(current_length > max_length):
max_length = current_length
idx_after = i
idx_before = idx_prev_delimiter
current_length = 0
idx_prev_delimiter = i
else:
current_length += 1
if(current_length > max_length):
idx_before = idx_prev_delimiter
idx_after = len(string)
return string[idx_before + 1: idx_after]
string = ",algorytm.schemat blokowy. b." # string_from_file(path_to_file)
longest_word(string)