about summary refs log tree commit diff
path: root/2ndary/12/TP-ThanhHoá-2009/bai3.pas
blob: a98141e92bdf100912629eb98f833d51e4f5050c (plain) (blame)
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
39
40
41
42
43
44
var
  f: text;
  s: string;
  min: byte = 255;


procedure palen(
  s: string;
  tmp: smallint
);

  begin
    if tmp + length(s) >= min then
      exit;

    if length(s) < 2 then
      begin
        min := tmp + length(s);
        exit
      end;

    if s[1] = s[length(s)] then
      palen(copy(s, 2, length(s) - 2), tmp + 2)
    else
      begin
        palen(copy(s, 2, length(s) - 1), tmp + 2);
        palen(copy(s, 1, length(s) - 1), tmp + 2)
      end
  end;


begin
  assign(f, 'BAI3.INP');
  reset(f);
  read(f, s);
  close(f);

  palen(s, -length(s));

  assign(f, 'BAI3.OUT');
  rewrite(f);
  writeln(f, min);
  close(f)
end.