aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/abigail/pascal/ch-2.p
blob: f7328d3a0d58d33d0fbefaf2320aa014d460c365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Program ch2;

(*                  *)
(* See ../README.md *)
(*                  *)

(*                                                        *)
(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
(*                                                        *)

uses
    StrUtils, fgl;

var
    line: string;
    i, j: integer;
    substr: string;
    palindromes: specialize TFPGMap <string, boolean>;

begin
    while not eof do begin
        palindromes := specialize TFPGMap <string, boolean> . Create;
        readln (line);
        for i := 1 to length (line) do begin
            for j := i to length (line) do begin
                substr := copy (line, i, j - i + 1);
                if substr = ReverseString (substr) then begin
                    if palindromes . IndexOf (substr) = -1 then begin
                        write (substr, ' ');
                        palindromes . Add (substr, true);
                    end
                end
            end
        end;
        writeln ('');
        palindromes . Free;
    end
end.