Cod sursa(job #2267626)

Utilizator rares9301Sarmasag Rares rares9301 Data 23 octombrie 2018 20:05:25
Problema Invers Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.66 kb

#include<cstdio>

#include<cmath>

using namespace std;

int v[10005];

int main(){

freopen("invers.in","r",stdin);

freopen("invers.out","w",stdout);

int t,i1,n,st,dr,st2,dr2,trprev,trfron,cif,num;

char ch;

scanf("%d\n",&t);

for(i1=1;i1<=t;i1++){

ch=getchar();

n=0;

while(ch!='\n'){

v[++n]=ch-'0';

ch=getchar();}

st=1;

dr=n;

trprev=0;

trfron=0;

while(st<=dr){

cif=(v[dr]-trfron+10)%10;

if (trprev && cif!=9)

cif=cif+10;

if (st==1 && cif==0)

break;

if (dr==st+1){

num=trprev*100+v[st]*10+v[dr]-trfron;

if (cif*11!=num)

break;}

if (st==dr && cif%2==1)

break;

if (cif>18)

break;

if (v[st]==cif%10 && cif==9 && trprev)

break;

if (v[st]==(cif+1)%10 && cif==9 && trprev==0)

break;

if (v[st]!=cif%10 && v[st]!=(cif+1)%10)

break;

if (v[st]!=cif%10)

trprev=1;

else

trprev=0;

if (cif+trfron>=10)

trfron=1;

else

trfron=0;

st++;

dr--;}

st2=0;

dr2=1;

if (v[1]==1 && n!=1){

st2=2;

dr2=n;

trprev=1;

trfron=0;

while(st2<=dr2){

cif=(v[dr2]-trfron+10)%10;

if (trprev && cif!=9)

cif=cif+10;

if (dr2==st2+1){

num=trprev*100+v[st2]*10+v[dr2]-trfron;

if (cif*11!=num)

break;}

if (st2==dr2 && cif%2==1)

break;

if (cif>18)

break;

if (v[st2]==cif%10 && cif==9 && trprev)

break;

if (v[st2]==(cif+1)%10 && cif==9 && trprev==0)

break;

if (v[st2]!=cif%10 && v[st2]!=(cif+1)%10)

break;

if (v[st2]!=cif%10)

trprev=1;

else

trprev=0;

if (cif+trfron>=10)

trfron=1;

else

trfron=0;

st2++;

dr2--;}}

if (st>dr || st2>dr2)

printf("DA\n");

else

printf("NU\n");}

return 0;}