Longest common suffix: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: added syntax colouring, marked p2js compatible |
Longest common suffix en FreeBASIC |
||
Line 1,340:
""
</pre>
=={{header|FreeBASIC}}==
{{trans|Ring}}
<lang freebasic>Dim As String pre(1 To ...) = {"baabababc","baabc","bbbabc"}
Dim As Integer longitud = Ubound(pre)
Dim As Integer lenList(longitud)
Dim As Integer n, m, longest
Dim As String temp
Function rever(Byval text As String) As String
Dim As String text2 = text
Dim As Integer x, lt = Len(text)
For x = 0 To lt Shr 1 - 1
Swap text2[x], text2[lt - x - 1]
Next x
Return text2
End Function
Print "There are"; longitud; " words in the list: ";
For n = 1 To longitud
Print pre(n); " ";
temp = pre(n)
pre(n) = rever(temp)
lenList(n) = Len(pre(n))
Next n
For m = 1 To lenList(1)
Dim As String sub1 = Mid(pre(1),1,m)
Dim As String sub2 = Mid(pre(2),1,m)
Dim As String sub3 = Mid(pre(3),1,m)
If sub1 = sub2 And sub2 = sub3 Then longest = m
Next m
Dim As String longPrefix = Mid(pre(1),1,longest)
longPrefix = rever(longPrefix)
Print !"\n\nThe longest common suffix is: "; longPrefix
Sleep</lang>
{{out}}
<pre>There are 3 words in the list: baabababc baabc bbbabc
The longest common suffix is: abc</pre>
=={{header|Go}}==
|