Longest palindromic substrings: Difference between revisions

Content added Content deleted
(Added solution for Action!)
Line 45: Line 45:
'drome' -> 'e'
'drome' -> 'e'
'the abbatial palace' -> 'abba'
'the abbatial palace' -> 'abba'
</pre>

=={{header|Action!}}==
<lang Action!>BYTE FUNC Palindrome(CHAR ARRAY s)
BYTE l,r

l=1 r=s(0)
WHILE l<r
DO
IF s(l)#s(r) THEN RETURN (0) FI
l==+1 r==-1
OD
RETURN (1)

PROC Find(CHAR ARRAY text,res)
BYTE first,len
len=text(0)
WHILE len>0
DO
FOR first=1 TO text(0)-len+1
DO
SCopyS(res,text,first,first+len-1)
IF Palindrome(res) THEN
RETURN
FI
OD
len==-1
OD
res(0)=0
RETURN

PROC Test(CHAR ARRAY text)
CHAR ARRAY res(100)

Find(text,res)
PrintF("""%S"" -> ""%S""%E",text,res)
RETURN

PROC Main()
Test("three old rotators")
Test("never reverse")
Test("abracadabra")
Test("the abbatial palace")
Test("qwertyuiop")
Test("")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Longest_palindromic_substrings.png Screenshot from Atari 8-bit computer]
<pre>
"three old rotators" -> "rotator"
"never reverse" -> "ever reve"
"abracadabra" -> "aca"
"the abbatial palace" -> "abba"
"qwertyuiop" -> "q"
"" -> ""
</pre>
</pre>