Cod sursa(job #1008120)

Utilizator hungntnktpHungntnktp hungntnktp Data 10 octombrie 2013 11:14:10
Problema Iv Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.42 kb
Const
  tfi =   'iv.in';
  tfo =   'iv.out';
Var
  st1,st2,st  : string;
  fi,fo       : text;
  n,m,res     : longint;
(*-------------------------*)
Procedure nhap;
  Begin
     assign(fi,tfi); reset(fi);
       readln(fi,st1);
       readln(fi,st2);
       n := length(st1);
       m := length(st2);
     close(fi);
  End;
(*-------------------------*)
procedure init;
  Begin
     st:='';
     res := 0;
  End;
(*-------------------------*)
Function is_pali(x : string): boolean;
  Var
    i  :  longint;
  Begin
    for i := 1 to length(x) div 2 do
       if x[i] <> x[length(x)-i+1] then exit(false);
    exit(true);
  End;
(*-------------------------*)
Procedure perfect;
  Var
     i  : longint;
  Begin
     if is_pali(st) then inc(res);
  End;
(*-------------------------*)
Procedure try(i,j: longint);
  Begin
    if (i=n+1) and (j=m+1) then
       begin
         perfect;
         exit;
       end;
     if i <= n then
      begin
        st := st + st1[i];
        try(i+1,j);
        delete(st,length(st),1);
      end;
     if j <= m then
       begin
          st := st + st2[j];
          try(i,j+1);
          delete(st,length(st),1);
       end;
  End;
(*-------------------------*)
Procedure inkq;
  Begin
     assign(fo,tfo); rewrite(fo);
       write(fo,res);
     close(fo);
  End;
(*-------------------------*)
Begin
  nhap;
  init;
  try(1,1);
  inkq;
End.