Nhập vào 1 xâu .Đưa ra từ đối xứng dài nhất. Cảm ơn 🥰
1 câu trả lời
program xaudoixung;
uses crt;
var s,st,st2:string;
i,j,max:byte;
function ktdx(str:string):boolean;
var str1:string;
l:byte;
begin
str1:='';
for l:=length(str) downto 1 do
str1:=str1+str[l];
if str1=str then ktdx:=true else ktdx:=false;
end;
BEGIN
clrscr;
write('Nhap xau: '); readln(s);
st:=s[1]; max:=1;
for i:=1 to length(s)-1 do
begin
st2:='';
for j:=i to length(s) do
begin
st2:=st2+s[j];
if ktdx(st2) and (length(st2)>max) then
begin
st:=st2;
max:=length(st);
end;
end;
end;
write('Xau doi xung dai nhat la: ',st);
readln;
end.