Cod sursa(job #137657)

Utilizator portocalaDiculescu Elena Alexandra portocala Data 17 februarie 2008 12:52:34
Problema Nivele Scor 20
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasele 11-12 Marime 0.55 kb
#include<fstream.h>
ifstream f("nivele.in");
ofstream g("nivele.out");
int t,ok;
long n;
long citire(long pre,long po)
{if(!n)
 {ok=1;
  if(po!=pre)
   return 0;
  return po-1;
  }
if(n)
 {long x;
  while((po!=pre)&&po)
   {f>>x;n--;
    po=citire(po,x);
   }
  
  if(!po)return 0;
  if(po==1)
   {if(ok)return 1;
    return 0;
    }
  return po-1;
 }

return 0;
}

int main()
{f>>t;
long x;
while(t)
{f>>n>>x;n--;
 ok=0;
 x=citire(1,x);
 if(x)g<<"DA"<<'\n';
  else g<<"NU"<<'\n';
 t--;
}
f.close();
g.close();
return 0;
}