program StringheDaFilePalindrome;
const
LunghezzaMax = 500;
type
TipoIndice = 1..LunghezzaMax;
TipoArrayStringa = packed array [TipoIndice] of char;
TipoStringa = record
caratteri : TipoArrayStringa;
lunghezza : 0..LunghezzaMax
end;
procedure LeggiStringa (var stringa: TipoStringa);
var
continua : boolean;
nome : string;
f : text;
begin
writeln('Nome del file contenente la stringa? ');
readln(nome);
Assign(f, nome);
Reset(f);
continua := TRUE;
with stringa do
begin
lunghezza := 0;
while (not eof(f)) and continua do
begin
if lunghezza < LunghezzaMax then
begin
lunghezza := lunghezza + 1;
read(f, caratteri[lunghezza])
end
else
begin
continua := FALSE;
writeln ('File troppo lungo!')
end
end
end;
Close(f)
end;
function Palindroma (stringa: TipoStringa): boolean;
var
i : TipoIndice;
begin
Palindroma := TRUE;
for i := 1 to trunc(stringa.lunghezza/2) do
if stringa.caratteri[i] <> stringa.caratteri[stringa.lunghezza-i+1] then
Palindroma := FALSE
end;
var
s : TipoStringa;
begin
LeggiStringa(s);
write('La stringa letta contiene ', s.lunghezza, ' caratteri ');
if Palindroma(s) then
writeln('ed e'' palindroma')
else
writeln('e non e'' palindroma');
end.