Longest palindromic substrings: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 30: Line 30:


see "Input: " + st + nl
see "Input: " + st + nl
see "Longest palindromic subStrings:" + nl
see "Longest palindromic substrings:" + nl
see resList
see resList
</lang>
</lang>

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