Pagini recente » Cod sursa (job #842161) | Cod sursa (job #1026204)
{$h+}
CONST
tfi ='invers.in';
tfo ='invers.out';
nmax =10000;
TYPE
arr =array [1..nmax] of longint;
VAR
fi,fo :text;
s :string;
t,i :longint;
p :arr;
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 (p[j]<>nho) then exit(false);
exit(true);
end;
u:=ord(s[i])-48;
v:=(ord(s[j])-48-nho+10) mod 10;
if (u=0) and (v=9) and (p[i-1]=0) then exit(false);
if (i=j) then
begin
if v mod 2=1 then exit(false);
end;
p[i]:=(u-v+10) mod 10;
if (i=j-1) and (u=9) and (v=9) and (nho=1) then exit(false);
if (v=9) and (k=1) then
begin
if u<>0 then exit(false) else get:=get(i+1,j-1,1,nho);
end
else get:=get(i+1,j-1,p[i],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 (not((s[1]='1') and (s[length(s)]='0'))) then dd:=get(1,length(s),0,0);
if (dd=false) and (s[1]='1') then
begin
p[1]:=1;
dd:=get(2,length(s),1,0);
end;
if dd then writeln(fo,'DA') else writeln(fo,'NU');
end;
dec(t);
end;
close(fi);
close(fo);
END.