Pagini recente » Cod sursa (job #448733) | Cod sursa (job #1507667) | Cod sursa (job #76956) | Cod sursa (job #557730) | Cod sursa (job #2759239)
#include <fstream>
#include <stack>
using namespace std;
ifstream fin("nivele.in");
ofstream fout("nivele.out");
int n,q;
int main()
{
int i,x,j;
fin>>q;
for(j=1;j<=q;++j)
{
fin>>n;
stack <int> S;
for(i=1;i<=n;++i)
{
fin>>x;
if(S.empty())S.push(x);
else
{
if(S.top()!=x)S.push(x);
else
{
while(!S.empty()&&S.top()==x)/// x=1
{
S.pop();
x--;
}
S.push(x);
}
}
}
if(!S.empty()&&S.top()==1)fout<<"DA\n";
else fout<<"NU\n";
}
return 0;
}