Longest palindromic substrings: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Minor tidy) |
(Added FreeBASIC) |
||
Line 337: | Line 337: | ||
A longest palindromic substring of "" is "" |
A longest palindromic substring of "" is "" |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="vbnet">Function isPalindrome(s As String) As Integer |
|||
For i As Integer = 1 To Len(s) / 2 |
|||
If Mid(s, i, 1) <> Mid(s, Len(s) - i + 1, 1) Then Return False |
|||
Next i |
|||
Return True |
|||
End Function |
|||
Sub LongestPalindrome(s As String) |
|||
Dim As String substr, longest = "" |
|||
Dim As Integer i, j |
|||
For i = 1 To Len(s) |
|||
For j = i To Len(s) |
|||
substr = Mid(s, i, j - i + 1) |
|||
If isPalindrome(substr) Andalso Len(substr) > Len(longest) Then longest = substr |
|||
Next j |
|||
Next i |
|||
Print "The longest palindromic substring is/are: " |
|||
For i = 1 To Len(s) |
|||
For j = i To Len(s) |
|||
substr = Mid(s, i, j - i + 1) |
|||
If IsPalindrome(substr) Andalso Len(substr) = Len(longest) Andalso Len(substr) > 2 Then Print substr; " "; |
|||
Next j |
|||
Next i |
|||
If Len(longest) <= 2 Then Print "<no palindromic substring of two of more letters found>" |
|||
End Sub |
|||
Dim s As String |
|||
Input "Enter a string: ", s |
|||
LongestPalindrome(s) |
|||
Sleep</syntaxhighlight> |
|||
=={{header|Go}}== |
=={{header|Go}}== |