Cod sursa(job #1026172)

Utilizator hungntnktpHungntnktp hungntnktp Data 11 noiembrie 2013 11:07:15
Problema Invers Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.68 kb
CONST
        tfi     ='invers.in';
        tfo     ='invers.out';
VAR
        fi,fo   :text;
        s       :string;
        t       :longint;
        dd      :boolean;
 (************************************************************************)
Function get(i,j,k,nho:longint):boolean;
      Var
        u,v     :longint;
      Begin
        if k>1 then exit(false);
        if i>j then
          begin
            if (nho<>k) then exit(false);
            exit(true);
          end;
        u:=ord(s[i])-48;
        v:=(ord(s[j])-48-nho+10) mod 10;
        if (i=j) then
          begin
            if v mod 2=0 then exit(true) else exit(false);
          end;
        if (v=9) and (k=1) then
          begin
            if u<>0 then exit(false) else get:=get(i+1,j-1,1,0);
          end
        else get:=get(i+1,j-1,(u-v+10) mod 10,k);
      End;
 (************************************************************************)
BEGIN
      assign(fi,tfi);reset(fi);
      assign(fo,tfo);rewrite(fo);
        readln(fi,t);
        while t<>0 do
          begin
            readln(fi,s);
            if length(s)=1 then
              begin
                if (s='0') or (s='2') or (s='4') or (s='6') or (s='8') then writeln(fo,'DA') else writeln(fo,'NU');
              end
            else
              begin
                dd:=false;
                if NUt((s[1]='1') and (s[length(s)]='0')) then dd:=get(1,length(s),0,0);
                if (dd=false) and (s[1]='1') then dd:=get(2,length(s),1,0);
                if dd then writeln(fo,'DA') else writeln(fo,'NU');
              end;
            dec(t);
          end;
      close(fi);
      close(fo);
END.