Cod sursa(job #2154763)

Utilizator ovidius11Stiriu Ovidius ovidius11 Data 7 martie 2018 11:52:28
Problema Invers Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 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;
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==dr && cif%2==1)
break;
if (cif>18)
break;
if (v[st]==cif%10 && cif==9 && trprev)
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 (st2==dr2 && cif%2==1)
break;
if (cif>18)
break;
if (v[st2]==cif%10 && cif==9 && trprev)
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;}