Помогите пожалуйста!!!
Добавлено: 26 дек 2013, 02:35
Паскаль: В тексте найти одну пару [все пары] слов, из которых одно является обращением другого (например, “abcd” и “dcba”).
Код: Выделить всё
var
str: string;
TxtLen,L,P1,P2: integer;
function CheckPair(const str:string; pos1:integer; pos2:integer; len:integer):boolean;
var i:integer;
begin
for i:=1 to len do if str[pos1+i-1]<>str[pos2+len-i] then begin
CheckPair:=false;
exit;
end;
CheckPair:=true;
end;
begin
write('input text:'); readln(str);
TxtLen:=length(str);
for L:=2 to trunc(TxtLen/2) do begin
writeln('Searching for words with length ',L,'...');
for P1:=1 to L do begin
for P2:=P1+L to TxtLen-L+1 do begin
if CheckPair(str,P1,P2,L) then writeln('Pair was found. "',copy(str,P1,L),'"@',P1,' and "',copy(str,P2,L),'"@',P2);
end;
end;
end;
end.