Longest substrings without repeating characters: Difference between revisions

add FreeBASIC
(Add C)
(add FreeBASIC)
Line 346:
"a" -> { "a" }
"" -> { }
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>dim as string example = "antidisestablishmentarianism is a long word and so is flibbertigibbet."
 
function nrls( t as string ) as string
dim as integer best=0, best_length=-100, i=1, j, k, curr_length
dim as string c
for i = 1 to len(t)+1
curr_length = 0
for j = i+1 to len(t)+1
curr_length += 1
c = mid(t, j, 1)
for k = i to j - 1
if c = mid(t, k, 1) then goto nexti
next k
next j
nexti:
if curr_length > best_length then
best_length = curr_length
best = i
end if
next i
return mid(t, best, best_length)
end function
 
print ">";nrls(example);"<"
print ">";nrls("My spoon is too big.");"<"
print ">";nrls("Rosetta Code.");"<"
print ">";nrls("AAAAA");"<"
print ">";nrls("abcdefghijklmnopqrstuvwxyz");"<"
print ">";nrls("aaa aeiou uuu");"<"
</lang>
{{out}}<pre>
>blishmentar<
>My spo<
>ta Code.<
>A<
>abcdefghijklmnopqrstuvwxyz<
> aeiou<
</pre>
 
781

edits