Longest palindromic substrings

Revision as of 10:45, 28 September 2020 by CalmoSoft (talk | contribs) (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 = [...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Let given a string s. The goal is to find the longest palindromic substring in s.

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.

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