RosettaCodeData/Task/Longest-string-challenge/Run-BASIC/longest-string-challenge-2....

27 lines
883 B
Plaintext

strings$ = "a bb ccc ddd ee f ggg" ' The given string data
while word$(strings$,numWords + 1," ") <> "" ' Count the words
numWords = numWords + 1
wend
dim string$(numWords) ' Dimension the string with the word cound
for j = 1 to numWords
string$(j) = word$(strings$,j," ") ' put the words from the string into the string array
next j
h$ = "1"
while h$ <> "" ' The good old simple bubble sort
h$ = ""
for i = 1 to numWords -1
if len(string$(i)) < len(string$(i+1)) then ' sort by length descending
h$ = string$(i)
string$(i) = string$(i+1)
string$(i+1) = h$
end if
next i
wend
for i = 1 to numWords
print len(string$(i));" ";string$(i) ' print out the words in length descending sequence
next i