Longest palindromic substrings: Difference between revisions
Content added Content deleted
(Created page with "{{draft task}} Let given a string s. The goal is to find the longest palindromic substring in s. =={{header|Ring}}== <lang ring> load "stdlib.ring" st = "babaccd" palList = [...") |
|||
Line 36: | Line 36: | ||
<pre> |
<pre> |
||
Input: babaccd |
Input: babaccd |
||
Longest palindromic |
Longest palindromic substrings: |
||
bab |
bab |
||
aba |
aba |
Revision as of 10:51, 28 September 2020
Longest palindromic substrings is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Let given a string s. The goal is to find the longest palindromic substring in s.
Ring
<lang ring> load "stdlib.ring"
st = "babaccd" palList = []
for n = 1 to len(st)-1
for m = n+1 to len(st) sub = substr(st,n,m-n) if ispalindrome(sub) and len(sub) > 1 add(palList,[sub,len(sub)]) ok next
next
palList = sort(palList,2) palList = reverse(palList) resList = [] add(resList,palList[1][1])
for n = 2 to len(palList)
if palList[1][2] = palList[n][2] add(resList,palList[n][1]) ok
next
see "Input: " + st + nl see "Longest palindromic subStrings:" + nl see resList </lang>
- Output:
Input: babaccd Longest palindromic substrings: bab aba